Prevent ReDoS in Spanish sentence splitting regex#1084
Merged
Gallaecio merged 3 commits intoscrapinghub:masterfrom Jan 11, 2023
Merged
Prevent ReDoS in Spanish sentence splitting regex#1084Gallaecio merged 3 commits intoscrapinghub:masterfrom
Gallaecio merged 3 commits intoscrapinghub:masterfrom
Conversation
Gallaecio
approved these changes
Jan 11, 2023
Contributor
|
Closing and reopening to re-trigger CI jobs… |
In Spanish, questions start with an upside down question mark: > ¿Vos bueno? This was already handled in the original regex, but the original regex was vulnerable for regular expression denial of service (ReDoS). In the new regex, we either search for normal end-of-sentence optionally followed by a ¿ or ¡, or a ¿ or ¡ on its own. A change is that the normal end-of-sentence (.!?;…) has to come before the ¡ or ¿, but I think this is acceptable. This PR also adds some Spanish test cases. These hit the sentence splitting logic, but the exact result of the splitting is not tested. Fixes scrapinghub#869
Consume whitespace if there is any, but still match if there isn't. This makes most sense for \n followed immediately by ¿. This also means we don't have to backtrack if there isn't any whitespace after a line ending.
fe59143 to
ef78400
Compare
Contributor
Author
|
I rebased to master. |
The previous code wouldn't remove multiple empty strings in a row, due to modifying the list during the loop. We use `filter` with the default identity function instead.
serhii73
approved these changes
Jan 11, 2023
wRAR
approved these changes
Jan 11, 2023
Collaborator
|
We have a new release with this PR. Thank you @Sjord |
13 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
In Spanish, questions start with an upside down question mark:
This was already handled in the original regex, but the original regex was vulnerable for regular expression denial of service (ReDoS). In the new regex, we either search for normal end-of-sentence optionally followed by a ¿ or ¡, or a ¿ or ¡ on its own. A change is that the normal end-of-sentence (.!?;…) has to come before the ¡ or ¿, but I think this is acceptable.
This PR also adds some Spanish test cases. These hit the sentence splitting logic, but the exact result of the splitting is not tested.
Fixes #869