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

Correctly skip plus-prefixed URLs #21

Merged
merged 5 commits into from
Dec 9, 2018
Merged
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
1 change: 0 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,3 @@ language: node_js
node_js:
- '10'
- '8'
- '6'
2 changes: 1 addition & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
const createHtmlElement = require('create-html-element');

// Capture the whole URL in group 1 to keep string.split() support
const urlRegex = () => (/((?:https?(?::\/\/))(?:www\.)?(?:[a-zA-Z\d-_.]+(?:(?:\.|@)[a-zA-Z\d]{2,})|localhost)(?:(?:[-a-zA-Z\d:%_+.~#!?&//=@]*)(?:[,](?![\s]))*)*)/g);
const urlRegex = () => (/((?<!\+)(?:https?(?::\/\/))(?:www\.)?(?:[a-zA-Z\d-_.]+(?:(?:\.|@)[a-zA-Z\d]{2,})|localhost)(?:(?:[-a-zA-Z\d:%_+.~#!?&//=@]*)(?:[,](?![\s]))*)*)/g);

// Get <a> element as string
const linkify = (href, options) => createHtmlElement({
Expand Down
6 changes: 6 additions & 0 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,12 @@ linkifyUrls('See https://sindresorhus.com/foo', {
//=> 'See <a href="https://sindresorhus.com/foo">/foo</a>'
```

## Compatibility note

Since v2.2.0, the main regular expression is using a negative look-behind to address [#7](https://github.com/sindresorhus/linkify-urls/issues/7).
Look-behind assertions [should be compatible since Node v6](https://node.green/#ES2018-features--RegExp-Lookbehind-Assertions) (with the use of `--harmony` flag).
At the time of this note, only Google Chrome seems to support it, even though it [will eventually be a standard](https://tc39.github.io/ecma262/).
sindresorhus marked this conversation as resolved.
Show resolved Hide resolved


## Related

Expand Down
2 changes: 1 addition & 1 deletion test.js
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ test('supports `value` option as function', t => {
}), 'See <a href="https://github.com/sindresorhus.com/linkify-urls">github.com</a> for a solution');
});

test.failing('skips Git URLs', t => {
test('skips URLs preceded by a `+` sign', t => {
const fixture = 'git+https://github.com/sindresorhus/ava';
t.is(m(fixture), fixture);
});
Expand Down