misd-service-development / php-linkify

Converts URLs and email addresses into HTML links
MIT License
112 stars 17 forks source link

Backtrack limit hit with unbalanced parenthesis #14

Closed arthurdarcet closed 7 years ago

arthurdarcet commented 9 years ago

Trying to processUrl the string ftp://(123456789012345678 will result in a PREG_BACKTRACK_LIMIT_ERROR (I think it has something to do with this ).

I don't understand why the linkifyUrl regex is trying to match balanced parenthesis, the above URL should be considered valid and there isn't any reason for ( or < to be balanced in an URL. (real life example: http://i.ebayimg.com/00/s/MTYwMFgxMDg5/$(KGrHqYOKjIE6Sv7R)(rBOw8jhvfD!~~60_35.JPG )

thewilkybarkid commented 8 years ago

Bit late to reply, but the balancing is to cater for cases like Composer (further details at https://en.wikipedia.org/wiki/Composer_(software)) (the second closing parenthesis shouldn't form part of it).

bartgloudemans commented 7 years ago

Also without surrounding parentheses this bug occurs:
https://example.com/x_(aaaaaaaaaaaaaaaaa) (17 times 'a') will fail by resulting in a PREG_BACKTRACK_LIMITERROR
`https://example.com/x
(aaaaaaaaaaaaaaaa)will successfully return a match (16 times 'a') https://example.com/x_(aaaaaaaaaaaaaaaaa)b` succeeds again (17 times 'a')