Swift: Recognize regular expression parse mode flags #13715
+293
−74
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.


Recognize regular expression parse mode flags in Swift. For example in
(?i)foo, the(?i)specifies a case-insensitive match of the rest of the regular expressionfoo.This improves the accuracy of the REDOS and bad HTML filtering queries (and others to come).
Limitations:
foo(?i)bar, which is allowed in Swift(?i:foo)bar, which is allowed in Swift(?i-s), which is allowed in Swift@erik-krogh @joefarebrother the initial version of this was based on code from Java and is also very similar to Python. I found that we were failing to recognize multiple mode flags (e.g.
(?is)), which I fixed with 6e80021. Please could you review those changes with a view to both correctness for Swift, and whether or not it would be desirable for me to port that fix to Java and/or Python?I'm also curious whether we support any of what I described in limitations 3-5 above in other languages. I suspect we do not, which makes it a pretty low priority for Swift where we're currently playing catch-up - but if we do it would be a starting point to solving them.