@@ -111,14 +111,23 @@ static void write_item(const char *what, LPCWSTR wbuf, int wlen)
111
111
* Match an (optional) expected string and a delimiter in the target string,
112
112
* consuming the matched text by updating the target pointer.
113
113
*/
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 )
115
124
{
116
125
LPCWSTR delim_pos , start = * ptarget ;
117
126
int len ;
118
127
119
128
/* find start of delimiter (or end-of-string if delim is empty) */
120
129
if (* delim )
121
- delim_pos = wcsstr (start , delim );
130
+ delim_pos = last ? wcsstr_last ( start , delim ) : wcsstr (start , delim );
122
131
else
123
132
delim_pos = start + wcslen (start );
124
133
@@ -138,6 +147,16 @@ static int match_part(LPCWSTR *ptarget, LPCWSTR want, LPCWSTR delim)
138
147
return !want || (!wcsncmp (want , start , len ) && !want [len ]);
139
148
}
140
149
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
+
141
160
static int match_cred (const CREDENTIALW * cred )
142
161
{
143
162
LPCWSTR target = cred -> TargetName ;
@@ -146,7 +165,7 @@ static int match_cred(const CREDENTIALW *cred)
146
165
147
166
return match_part (& target , L"git" , L":" ) &&
148
167
match_part (& target , protocol , L"://" ) &&
149
- match_part (& target , wusername , L"@" ) &&
168
+ match_part_last (& target , wusername , L"@" ) &&
150
169
match_part (& target , host , L"/" ) &&
151
170
match_part (& target , path , L"" );
152
171
}
0 commit comments