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

Add support to ie11 #1

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 13 additions & 14 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,20 @@
const ipRegex = require('ip-regex');
const tlds = require('tlds');

module.exports = options => {
options = {
strict: true,
...options
};
module.exports = function (options) {
options = Object.assign({strict: true}, options);

const protocol = `(?:(?:[a-z]+:)?//)${options.strict ? '' : '?'}`;
const auth = '(?:\\S+(?::\\S*)?@)?';
const ip = ipRegex.v4().source;
const host = '(?:(?:[a-z\\u00a1-\\uffff0-9][-_]*)*[a-z\\u00a1-\\uffff0-9]+)';
const domain = '(?:\\.(?:[a-z\\u00a1-\\uffff0-9]-*)*[a-z\\u00a1-\\uffff0-9]+)*';
const tld = `(?:\\.${options.strict ? '(?:[a-z\\u00a1-\\uffff]{2,})' : `(?:${tlds.sort((a, b) => b.length - a.length).join('|')})`})\\.?`;
const port = '(?::\\d{2,5})?';
const path = '(?:[/?#][^\\s"]*)?';
const regex = `(?:${protocol}|www\\.)${auth}(?:localhost|${ip}|${host}${domain}${tld})${port}${path}`;
var protocol = `(?:(?:[a-z]+:)?//)${options.strict ? '' : '?'}`;
var auth = '(?:\\S+(?::\\S*)?@)?';
var ip = ipRegex.v4().source;
var host = '(?:(?:[a-z\\u00a1-\\uffff0-9][-_]*)*[a-z\\u00a1-\\uffff0-9]+)';
var domain = '(?:\\.(?:[a-z\\u00a1-\\uffff0-9]-*)*[a-z\\u00a1-\\uffff0-9]+)*';
var tld = `(?:\\.${options.strict ? '(?:[a-z\\u00a1-\\uffff]{2,})' : `(?:${tlds.sort(function (a, b) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could be useful to list in the description the two changes that you make here:

  1. const to var
  2. remove arrow functions

return b.length - a.length;
}).join('|')})`})\\.?`;
var port = '(?::\\d{2,5})?';
var path = '(?:[/?#][^\\s"]*)?';
var regex = `(?:${protocol}|www\\.)${auth}(?:localhost|${ip}|${host}${domain}${tld})${port}${path}`;

return options.exact ? new RegExp(`(?:^${regex}$)`, 'i') : new RegExp(regex, 'ig');
};
14 changes: 12 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
{
"name": "url-regex",
"name": "@tactivos/url-regex",
"version": "5.0.0",
"description": "Regular expression for matching URLs",
"license": "MIT",
"repository": "kevva/url-regex",
"repository": {
"type": "git",
"url": "git://github.com/tactivos/url-regex.git"
},
"author": {
"name": "Kevin Mårtensson",
"email": "[email protected]",
Expand Down Expand Up @@ -32,5 +35,12 @@
"ava": "^1.4.1",
"tsd": "^0.7.2",
"xo": "^0.24.0"
},
"xo": {
"rules": {
"prefer-object-spread": 0,
"prefer-arrow-callback": 0,
"no-var": 0
}
}
}
5 changes: 5 additions & 0 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@

> Regular expression for matching URLs

## Source

Forked from [url-regex](https://github.com/kevva/url-regex) so we can improve the compability with IE11 or other browsers.
Needed for consuming it from surface hubs or windows app.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why we need this for the hubs and windows app ?

Copy link

@mfgea mfgea Jun 7, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

url-regex was imported as a regular dependency (meaning that it would not run through Babel), and it was recently upgraded because of security reasons. The thing is that in the upgrade, some non-ie11 compliant features were introduced (like arrow functions and const declarations) and it broke our windows apps.

The other option was to change the build process to include url-regex in the babel run, but this option is safer (and the lib is simple enough)


Based on this [gist](https://gist.github.com/dperini/729294) by Diego Perini.


Expand Down