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

Support scheme url starting with emoji #408

Open
wants to merge 1 commit 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
441 changes: 223 additions & 218 deletions dist/Autolinker.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/Autolinker.js.map

Large diffs are not rendered by default.

18 changes: 2 additions & 16 deletions dist/Autolinker.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/Autolinker.min.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion src/parser/tld-regex.ts

Large diffs are not rendered by default.

8 changes: 6 additions & 2 deletions src/parser/uri-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ export const tldUrlHostRe = /^(?:\/\/)?([^/#?:]+)/; // optionally prefixed with
* Determines if the given character may start a scheme (ex: 'http').
*/
export function isSchemeStartChar(char: string): boolean {
return letterRe.test(char);
return alphaNumericAndMarksRe.test(char);
}

/**
Expand All @@ -86,7 +86,11 @@ export function isSchemeStartChar(char: string): boolean {
*/
export function isSchemeChar(char: string): boolean {
return (
letterRe.test(char) || digitRe.test(char) || char === '+' || char === '-' || char === '.'
alphaNumericAndMarksRe.test(char) ||
digitRe.test(char) ||
char === '+' ||
char === '-' ||
char === '.'
);
}

Expand Down
16 changes: 11 additions & 5 deletions tests/autolinker-url.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,12 @@ describe('Autolinker Url Matching >', () => {
expect(result).toBe(`emoji url <a href="http://📙.la/🧛🏻‍♂️">📙.la/🧛🏻‍♂️</a> mid-sentance`);
});

it('should match urls with scheme starting with an emoji', function () {
const result = autolinker.link('emoji url 👉http://📙.la/🧛🏻‍♂️ mid-sentance');

expect(result).toBe(`emoji url 👉<a href="http://📙.la/🧛🏻‍♂️">📙.la/🧛🏻‍♂️</a> mid-sentance`);
});

it("should NOT autolink possible URLs with the 'javascript:' URI scheme", () => {
let result = autolinker.link("do not link javascript:window.alert('hi') please");
expect(result).toBe("do not link javascript:window.alert('hi') please");
Expand Down Expand Up @@ -758,7 +764,7 @@ describe('Autolinker Url Matching >', () => {
);
});

it(`should correctly accept square brackets such as PHP array
it(`should correctly accept square brackets such as PHP array
representation in query strings, when the entire URL is surrounded
by square brackets
`, () => {
Expand Down Expand Up @@ -984,11 +990,11 @@ describe('Autolinker Url Matching >', () => {
Sometimes you need to go to a path like yahoo.com/my-page
And hit query strings like yahoo.com?page=index
Port numbers on known TLDs are important too like yahoo.com:8000.
Hashes too yahoo.com:8000/#some-link.
Hashes too yahoo.com:8000/#some-link.
Sometimes you need a lot of things in the URL like https://abc123def.org/path1/2path?param1=value1#hash123z
Do you see the need for dashes in these things too https://abc-def.org/his-path/?the-param=the-value#the-hash?
There's a time for lots and lots of special characters like in https://abc123def.org/-+&@#/%=~_()|\'$*[]?!:,.;/?param1=value-+&@#/%=~_()|\'$*[]?!:,.;#hash-+&@#/%=~_()|\'$*[]?!:,.;z
Don't forget about good times with unicode https://ru.wikipedia.org/wiki/Кириллица?Кириллица=1#Кириллица
Don't forget about good times with unicode https://ru.wikipedia.org/wiki/Кириллица?Кириллица=1#Кириллица
and this unicode http://россия.рф
along with punycode http://xn--d1acufc.xn--p1ai
Oh good old www links like www.yahoo.com
Expand All @@ -1008,11 +1014,11 @@ describe('Autolinker Url Matching >', () => {
Sometimes you need to go to a path like <a href="http://yahoo.com/my-page">yahoo.com/my-page</a>
And hit query strings like <a href="http://yahoo.com?page=index">yahoo.com?page=index</a>
Port numbers on known TLDs are important too like <a href="http://yahoo.com:8000">yahoo.com:8000</a>.
Hashes too <a href="http://yahoo.com:8000/#some-link">yahoo.com:8000/#some-link</a>.
Hashes too <a href="http://yahoo.com:8000/#some-link">yahoo.com:8000/#some-link</a>.
Sometimes you need a lot of things in the URL like <a href="https://abc123def.org/path1/2path?param1=value1#hash123z">abc123def.org/path1/2path?param1=value1#hash123z</a>
Do you see the need for dashes in these things too <a href="https://abc-def.org/his-path/?the-param=the-value#the-hash">abc-def.org/his-path/?the-param=the-value#the-hash</a>?
There's a time for lots and lots of special characters like in <a href="https://abc123def.org/-+&@#/%=~_()|'$*[]?!:,.;/?param1=value-+&@#/%=~_()|'$*[]?!:,.;#hash-+&@#/%=~_()|'$*[]?!:,.;z">abc123def.org/-+&@#/%=~_()|'$*[]?!:,.;/?param1=value-+&@#/%=~_()|'$*[]?!:,.;#hash-+&@#/%=~_()|'$*[]?!:,.;z</a>
Don't forget about good times with unicode <a href="https://ru.wikipedia.org/wiki/Кириллица?Кириллица=1#Кириллица">ru.wikipedia.org/wiki/Кириллица?Кириллица=1#Кириллица</a>
Don't forget about good times with unicode <a href="https://ru.wikipedia.org/wiki/Кириллица?Кириллица=1#Кириллица">ru.wikipedia.org/wiki/Кириллица?Кириллица=1#Кириллица</a>
and this unicode <a href="http://россия.рф">россия.рф</a>
along with punycode <a href="http://xn--d1acufc.xn--p1ai">xn--d1acufc.xn--p1ai</a>
Oh good old www links like <a href="http://www.yahoo.com">www.yahoo.com</a>
Expand Down
Loading