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
…ion limit
The repeat count limit of 1000 was hardcoded as a magic number in
multiple places. Extract it into a named constant maxRepeat for 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 rejected
because 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 golang#78222
|
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. |
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