@@ -31,20 +31,17 @@ export function parse(string: string): Credentials | undefined {
3131
3232 // parse header
3333 const match = CREDENTIALS_REGEXP . exec ( string ) ;
34-
35- if ( ! match ) {
36- return undefined ;
37- }
34+ if ( ! match ) return undefined ;
3835
3936 // decode user pass
40- const userPass = USER_PASS_REGEXP . exec ( decodeBase64 ( match [ 1 ] ) ) ;
41-
42- if ( ! userPass ) {
43- return undefined ;
44- }
45-
46- // return credentials object
47- return new CredentialsImpl ( userPass [ 1 ] , userPass [ 2 ] ) ;
37+ const userPass = decodeBase64 ( match [ 1 ] ) ;
38+ const colonIndex = userPass . indexOf ( ':' ) ;
39+ if ( colonIndex === - 1 ) return undefined ;
40+
41+ return {
42+ name : userPass . slice ( 0 , colonIndex ) ,
43+ pass : userPass . slice ( colonIndex + 1 ) ,
44+ } ;
4845}
4946
5047/**
@@ -59,17 +56,6 @@ export function parse(string: string): Credentials | undefined {
5956const CREDENTIALS_REGEXP =
6057 / ^ * (?: [ B b ] [ A a ] [ S s ] [ I i ] [ C c ] ) + ( [ A - Z a - z 0 - 9 . _ ~ + / - ] + = * ) * $ / ;
6158
62- /**
63- * RegExp for basic auth user/pass
64- *
65- * user-pass = userid ":" password
66- * userid = *<TEXT excluding ":">
67- * password = *TEXT
68- * @private
69- */
70-
71- const USER_PASS_REGEXP = / ^ ( [ ^ : ] * ) : ( .* ) $ / ;
72-
7359/**
7460 * Decode base64 string.
7561 * @private
@@ -78,13 +64,3 @@ const USER_PASS_REGEXP = /^([^:]*):(.*)$/;
7864function decodeBase64 ( str : string ) : string {
7965 return Buffer . from ( str , 'base64' ) . toString ( ) ;
8066}
81-
82- class CredentialsImpl implements Credentials {
83- name : string ;
84- pass : string ;
85-
86- constructor ( name : string , pass : string ) {
87- this . name = name ;
88- this . pass = pass ;
89- }
90- }
0 commit comments