e260cc0330
The way JS RegExps handle anchored matches is to have a separate RegExp with `|()` added at the end, which means it either matches at that point, or the `()` matches at that point, and that's visible in the captures as a non-`null` last capture group. The same RegExp is used to find the number of captures a RegExp has, by running it on an empty string, and seeing the length of the capture array, even if it contains nothing but `null` and `""` values. The RegExp is as JS global regexp, which is what allows it to start matching at a specific point, which we use for `startsWith(Pattern, start)`. Every *normal* use of that RegExp remembers to set the `lastIndex` of the regexp before using it, but the `regExpCaptureCount` used the "anchored regexp" directly, and forgot to set the `lastIndex`, and since it had just been used and failed to match at a position *later* than the current input string's length, the "unfailable" test on the empty string failed, returning `null` where no `null` was expected. So now `regExpCaptureCount` sets `lastIndex` to zero before using the RegExp, like every use of a shared RegExp should. Fixes #56834 Bug: https://dartbug/com/56834 Change-Id: Ib649b70db5922c277950d7b7cfd4d157788d11cc Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/388002 Commit-Queue: Lasse Nielsen <lrn@google.com> Reviewed-by: Ömer Ağacan <omersa@google.com>