File tree Expand file tree Collapse file tree 2 files changed +32
-0
lines changed Expand file tree Collapse file tree 2 files changed +32
-0
lines changed Original file line number Diff line number Diff line change @@ -37,6 +37,7 @@ All Notable changes to `League\Uri\Interfaces` will be documented in this file
3737- ` Encoder::isFragmentEncoded `
3838- ` Encoder::normalizeUser `
3939- ` Encoder::normalizePassword `
40+ - ` Encoder::normalizeUserInfo `
4041- ` Encoder::normalizePath `
4142- ` Encoder::normalizeQuery `
4243- ` Encoder::normalizeFragment `
Original file line number Diff line number Diff line change 2121use SensitiveParameter ;
2222use Stringable ;
2323
24+ use function explode ;
2425use function filter_var ;
2526use function gettype ;
2627use function in_array ;
@@ -143,6 +144,36 @@ public static function isUserInfoEncoded(#[SensitiveParameter] Stringable|string
143144 && self ::isPasswordEncoded ($ password );
144145 }
145146
147+ public static function encodeUserInfo (#[SensitiveParameter] Stringable |string |null $ userInfo ): ?string
148+ {
149+ if (null === $ userInfo ) {
150+ return null ;
151+ }
152+
153+ [$ user , $ password ] = explode (': ' , (string ) $ userInfo , 2 ) + [1 => null ];
154+ $ userInfo = self ::encodeUser ($ user );
155+ if (null === $ password ) {
156+ return $ userInfo ;
157+ }
158+
159+ return $ userInfo .': ' .self ::encodePassword ($ password );
160+ }
161+
162+ public static function normalizeUserInfo (#[SensitiveParameter] Stringable |string |null $ userInfo ): ?string
163+ {
164+ if (null === $ userInfo ) {
165+ return null ;
166+ }
167+
168+ [$ user , $ password ] = explode (': ' , (string ) $ userInfo , 2 ) + [1 => null ];
169+ $ userInfo = self ::normalizeUser ($ user );
170+ if (null === $ password ) {
171+ return $ userInfo ;
172+ }
173+
174+ return $ userInfo .': ' .self ::normalizePassword ($ password );
175+ }
176+
146177 /**
147178 * Decodes all the URI component characters.
148179 */
You can’t perform that action at this time.
0 commit comments