@@ -111,14 +111,23 @@ static void write_item(const char *what, LPCWSTR wbuf, int wlen)
111111 * Match an (optional) expected string and a delimiter in the target string,
112112 * consuming the matched text by updating the target pointer.
113113 */
114- static int match_part (LPCWSTR * ptarget , LPCWSTR want , LPCWSTR delim )
114+
115+ static LPCWSTR wcsstr_last (LPCWSTR str , LPCWSTR find )
116+ {
117+ LPCWSTR res = NULL , pos ;
118+ for (pos = wcsstr (str , find ); pos ; pos = wcsstr (pos + 1 , find ))
119+ res = pos ;
120+ return res ;
121+ }
122+
123+ static int match_part_with_last (LPCWSTR * ptarget , LPCWSTR want , LPCWSTR delim , int last )
115124{
116125 LPCWSTR delim_pos , start = * ptarget ;
117126 int len ;
118127
119128 /* find start of delimiter (or end-of-string if delim is empty) */
120129 if (* delim )
121- delim_pos = wcsstr (start , delim );
130+ delim_pos = last ? wcsstr_last ( start , delim ) : wcsstr (start , delim );
122131 else
123132 delim_pos = start + wcslen (start );
124133
@@ -138,6 +147,16 @@ static int match_part(LPCWSTR *ptarget, LPCWSTR want, LPCWSTR delim)
138147 return !want || (!wcsncmp (want , start , len ) && !want [len ]);
139148}
140149
150+ static int match_part (LPCWSTR * ptarget , LPCWSTR want , LPCWSTR delim )
151+ {
152+ return match_part_with_last (ptarget , want , delim , 0 );
153+ }
154+
155+ static int match_part_last (LPCWSTR * ptarget , LPCWSTR want , LPCWSTR delim )
156+ {
157+ return match_part_with_last (ptarget , want , delim , 1 );
158+ }
159+
141160static int match_cred (const CREDENTIALW * cred )
142161{
143162 LPCWSTR target = cred -> TargetName ;
@@ -146,7 +165,7 @@ static int match_cred(const CREDENTIALW *cred)
146165
147166 return match_part (& target , L"git" , L":" ) &&
148167 match_part (& target , protocol , L"://" ) &&
149- match_part (& target , wusername , L"@" ) &&
168+ match_part_last (& target , wusername , L"@" ) &&
150169 match_part (& target , host , L"/" ) &&
151170 match_part (& target , path , L"" );
152171}
0 commit comments