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

Detect only well formed URLs by running them against a valid URL regex #5

Merged
merged 1 commit into from
Apr 2, 2017

Conversation

shubhamgoyal
Copy link
Contributor

To reproduce the issue that prompted this pull request, try including a URL preceded immediately by a character. For example,

ahttps://blog.glycoleap.com/herbal-chicken-brown-rice-congee-ultimate-asian-healing-food/

Notice the a before the URL. But Autolinker's URL parsing doesn't seem to be perfect and so, it treats the whole string as a URL and if you call match.getUrl(), it also adds the protocol before it. This leads to http://stackoverflow.com/questions/38099684/no-suitable-url-request-handler-found rather than the promise being gracefully rejected.

To solve this, I add a well recognised regex https://gist.github.com/dperini/729294 and use it to invalidate malformed URLs.

@ospfranco
Copy link
Collaborator

Well, now I'm wondering, if it were to re-validate URLs why use autolinker, might as well do something like string splitting and validate each piece against the regex.

@ospfranco ospfranco merged commit a2f0229 into OP-Engineering:master Apr 2, 2017
@shubhamgoyal
Copy link
Contributor Author

@ospfranco I agree with you there. It seems to be a waste to use autolinker now, would you like me to push a version without autolinker?

@ospfranco
Copy link
Collaborator

Already on it, will publish to npm in a few minutes.

@ospfranco
Copy link
Collaborator

Published under v1.1.0 release.

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

Successfully merging this pull request may close these issues.

None yet

2 participants