regexp/syntax: extract maxRepeat constant and document nested repetition limit#78232
regexp/syntax: extract maxRepeat constant and document nested repetition limit#78232kunwar-vikrant wants to merge 1 commit intogolang:masterfrom
Conversation
|
Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA). View this failed invocation of the CLA check for more information. For the most up to date status, view the checks section at the bottom of the pull request. |
|
This PR (HEAD: 35415d9) has been imported to Gerrit for code review. Please visit Gerrit at https://go-review.googlesource.com/c/go/+/756980. Important tips:
|
|
Message from Gopher Robot: Patch Set 1: Congratulations on opening your first change. Thank you for your contribution! Next steps: Most changes in the Go project go through a few rounds of revision. This can be During May-July and Nov-Jan the Go project is in a code freeze, during which Please don’t reply on this GitHub thread. Visit golang.org/cl/756980. |
|
Message from Olivier Mengué: Patch Set 1: (1 comment) Please don’t reply on this GitHub thread. Visit golang.org/cl/756980. |
|
Message from Alan Donovan: Patch Set 1: (1 comment) Please don’t reply on this GitHub thread. Visit golang.org/cl/756980. |
|
Message from Olivier Mengué: Patch Set 1: Code-Review+1 (1 comment) Please don’t reply on this GitHub thread. Visit golang.org/cl/756980. |
|
Message from Olivier Mengué: Patch Set 1: -Code-Review (1 comment) Please don’t reply on this GitHub thread. Visit golang.org/cl/756980. |
|
Message from Olivier Mengué: Patch Set 1: (1 comment) Please don’t reply on this GitHub thread. Visit golang.org/cl/756980. |
|
Message from Olivier Mengué: Patch Set 1: (1 comment) Please don’t reply on this GitHub thread. Visit golang.org/cl/756980. |
35415d9 to
fde35b5
Compare
|
This PR (HEAD: fde35b5) has been imported to Gerrit for code review. Please visit Gerrit at https://go-review.googlesource.com/c/go/+/756980. Important tips:
|
|
Message from Kunwar Vikrant: Patch Set 1: (2 comments) Please don’t reply on this GitHub thread. Visit golang.org/cl/756980. |
|
Message from Olivier Mengué: Patch Set 2: (1 comment) Please don’t reply on this GitHub thread. Visit golang.org/cl/756980. |
Extract the magic number 1000 used as the maximum repetition count
into a named constant maxRepeat in parse.go. This improves code
clarity and makes the limit easier to find and reason about.
The constant is used both in the repeat() method (via repeatIsValid)
and in the parse() function's bounds check for {n,m} forms.
Document the nested repetition product limit in doc.go: for nested
repetitions, the product of the repetition counts must not exceed
1000. This is a Go-specific implementation restriction enforced by
repeatIsValid in parse.go, extending the base restriction documented
in the RE2 distribution's syntax.txt:
https://github.com/google/re2/blob/main/doc/syntax.txt#L40
doc.go is generated by mksyntaxgo from the RE2 distribution:
https://github.com/google/re2/blob/main/doc/mksyntaxgo
The nested repetition product limit is Go-specific behavior not
present in RE2's syntax.txt, similar to the Go-specific Unicode
character class notes already added directly to doc.go.
Fixes golang#78222
fde35b5 to
a4b25cd
Compare
|
This PR (HEAD: a4b25cd) has been imported to Gerrit for code review. Please visit Gerrit at https://go-review.googlesource.com/c/go/+/756980. Important tips:
|
|
Message from Kunwar Vikrant: Patch Set 2: (1 comment) Please don’t reply on this GitHub thread. Visit golang.org/cl/756980. |
The repeat count limit of 1000 was hardcoded as a magic number in
multiple places. Extract it into a named constant
maxRepeatfor clarity.Additionally, the documentation stated that repeat counts above 1000
are rejected, but did not mention that nested repetitions have their
counts multiplied. For example,
(?:[a-z]{4}){0,251}is rejectedbecause the product 4*251=1004 exceeds 1000, even though neither
individual count does. Document this behavior.
Add test cases for the exact boundary:
{4}{250}(product 1000, valid)and
{4}{251}(product 1004, invalid).Fixes #78222