@@ -130,12 +130,14 @@ private unsafe int IndexOfOrdinalIgnoreCaseHelper(ReadOnlySpan<char> source, Rea
130
130
}
131
131
132
132
int startIndex , endIndex , jump ;
133
+ ReadOnlySpan < char > remainingSource ;
133
134
if ( fromBeginning )
134
135
{
135
136
// Left to right, from zero to last possible index in the source string.
136
137
// Incrementing by one after each iteration. Stop condition is last possible index plus 1.
137
138
startIndex = 0 ;
138
139
endIndex = source . Length - target . Length + 1 ;
140
+ remainingSource = source . Slice ( endIndex ) ;
139
141
jump = 1 ;
140
142
}
141
143
else
@@ -144,6 +146,7 @@ private unsafe int IndexOfOrdinalIgnoreCaseHelper(ReadOnlySpan<char> source, Rea
144
146
// Decrementing by one after each iteration. Stop condition is last possible index minus 1.
145
147
startIndex = source . Length - target . Length ;
146
148
endIndex = - 1 ;
149
+ remainingSource = source . Slice ( 0 , startIndex ) ;
147
150
jump = - 1 ;
148
151
}
149
152
@@ -192,6 +195,12 @@ private unsafe int IndexOfOrdinalIgnoreCaseHelper(ReadOnlySpan<char> source, Rea
192
195
Next : ;
193
196
}
194
197
198
+ // Before we return -1, check if the remaining source contains any special or non-Ascii characters.
199
+ if ( remainingSource . ContainsAnyExcept ( s_nonSpecialAsciiChars ) )
200
+ {
201
+ goto InteropCall ;
202
+ }
203
+
195
204
return - 1 ;
196
205
197
206
InteropCall :
@@ -246,12 +255,14 @@ private unsafe int IndexOfOrdinalHelper(ReadOnlySpan<char> source, ReadOnlySpan<
246
255
}
247
256
248
257
int startIndex , endIndex , jump ;
258
+ ReadOnlySpan < char > remainingSource ;
249
259
if ( fromBeginning )
250
260
{
251
261
// Left to right, from zero to last possible index in the source string.
252
262
// Incrementing by one after each iteration. Stop condition is last possible index plus 1.
253
263
startIndex = 0 ;
254
264
endIndex = source . Length - target . Length + 1 ;
265
+ remainingSource = source . Slice ( endIndex ) ;
255
266
jump = 1 ;
256
267
}
257
268
else
@@ -260,6 +271,7 @@ private unsafe int IndexOfOrdinalHelper(ReadOnlySpan<char> source, ReadOnlySpan<
260
271
// Decrementing by one after each iteration. Stop condition is last possible index minus 1.
261
272
startIndex = source . Length - target . Length ;
262
273
endIndex = - 1 ;
274
+ remainingSource = source . Slice ( 0 , startIndex ) ;
263
275
jump = - 1 ;
264
276
}
265
277
@@ -297,6 +309,12 @@ private unsafe int IndexOfOrdinalHelper(ReadOnlySpan<char> source, ReadOnlySpan<
297
309
Next : ;
298
310
}
299
311
312
+ // Before we return -1, check if the remaining source contains any special or non-Ascii characters.
313
+ if ( remainingSource . ContainsAnyExcept ( s_nonSpecialAsciiChars ) )
314
+ {
315
+ goto InteropCall ;
316
+ }
317
+
300
318
return - 1 ;
301
319
302
320
InteropCall :
0 commit comments