Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Regex for URI.withinString extremely slow on certain inputs #131

Closed
jsha opened this issue Jan 10, 2014 · 4 comments
Closed

Regex for URI.withinString extremely slow on certain inputs #131

jsha opened this issue Jan 10, 2014 · 4 comments
Labels

Comments

@jsha
Copy link

jsha commented Jan 10, 2014

I believe URI's regex for extracting URIs suffers from "catastrophic backtracking" (http://www.regular-expressions.info/catastrophic.html). Here's a repro case (runs in Node). I've also been able to reproduce the slowness in Chrome.

var URI = require("URIjs");
var input = "background-image:url('http://example.com/my/long/path/to/an/image.png')";
URI.withinString(input, function(u) { console.log(u); });

@rodneyrehm
Copy link
Member

I haven't written that URL-finder RegExp myself, I simply used one submitted to a url-regex-golfing thing we did ages ago.

Maybe Regex 101 can help with debugging. Also see Regexpr visualization

@rodneyrehm
Copy link
Member

I wonder if we shouldn't just use /\b(?:([a-z][\w-]+:\/\/)|www\.)[^\s]+/gi to find URLs, possibly containing trailing characters (closing brackets, dots, commas, …), and fix that in the replace() callback in withinString().

@jsha
Copy link
Author

jsha commented Jan 13, 2014

Yeah, I think that is probably the best approach.

rodneyrehm added a commit that referenced this issue Jan 23, 2014
…d allow filtering URLs by optional RegExp as well as ignore URLs in HTML - closing #117, #131
@rodneyrehm
Copy link
Member

The issue is resolved in v1.12.0 see the docs for an enhanced API.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants