spamscanner / url-regex-safe

Regular expression matching for URL's. Maintained, safe, and browser-friendly version of url-regex. Resolves CVE-2020-7661 for Node.js servers.
https://forwardemail.net/docs/url-regex-javascript-node-js
MIT License
79 stars 16 forks source link

Browser support #9

Open Richienb opened 3 years ago

Richienb commented 3 years ago

To properly support browsers, replace re2 with re2-wasm

niftylettuce commented 3 years ago

PR welcome

Richienb commented 3 years ago

Are you interested in dropping pre-build tooling and switching to ESM? This would make it easier to get the wasm-reliant code to work.

pjotrsavitski commented 2 years ago

@Richienb I tried to understand the difference between re2 and re2-wasm, but the second one seems to be based on the first and does not seem to have any major differences. Both modules seem to be useful on the Node.js server side and will not work within a browser. Why prefer second over the first?

Richienb commented 2 years ago

Why prefer second over the first?

You can not run native modules in the browser. You can run WASM though.

niftylettuce commented 2 years ago

When would we need url-regex-safe in the browser? Curious what the use cases are. Could just have an API endpoint that takes a string and parses it and returns it and then calls new RegExp with value?

Richienb commented 2 years ago

For libraries that validate urls before sending a request to them, making the validation an API endpoint would make this redundant. In this case, you might as well send the request in the first place and handle the error.

pjotrsavitski commented 2 years ago

I'm using it in the browser to create a version of the text that will have any URL's converted into HTML with newlines converted to line breaks. Using a module, which was url-regex, instead of my own regular expression made sense.

Having an API endpoint do that for each of the items in the listing does not seem like a good idea.