You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
If it is not enclosed, encountered bracket matches opening bracket of this group.
Otherwise, encountered bracket matches opening bracket of group with index depth, which is incorrect in general.
In example shown above, last closing bracket will enclose capturing group with index 1, which is foo, and not capturing group .*(2.). Moreover, this issue can be exploited with a wide range of regular expressions; demonstrated one is merely a proof of concept constructed from one of your unit tests.
How it shall be done
Encountered closing bracket shall match last unmatched opening bracket. One shall search for last capturing group, which length is set to -1, and not just assume capturing group with index depth.
A simple way to implement search_for_unmatched_bracket function
is to:
loop over brackets from the last position nbBrackets -1 to the first
Search and stop for the first unmatched ( where len == - 1) return the current position.
if not found, return -1
The bracket matching works perfectly but expression capture get faulty for expression like (a(b))(c) as the ))( is not well interpreted during capture.
Naive example
Regular expression
(foo)(.*(2.))
does not matchfoo123
.Explanation
This is due the incorrect processing of the closing bracket in
foo()
function:How it is done
depth
, which is incorrect in general.In example shown above, last closing bracket will enclose capturing group with index 1, which is
foo
, and not capturing group.*(2.)
. Moreover, this issue can be exploited with a wide range of regular expressions; demonstrated one is merely a proof of concept constructed from one of your unit tests.How it shall be done
Encountered closing bracket shall match last unmatched opening bracket. One shall search for last capturing group, which length is set to -1, and not just assume capturing group with index
depth
.Regards, Arseny.
The text was updated successfully, but these errors were encountered: