From 8297da3256901495c02af5d97988d50f93f7e239 Mon Sep 17 00:00:00 2001 From: Roy <40822827+roygold7@users.noreply.github.com> Date: Thu, 4 Oct 2018 11:41:10 +0300 Subject: [PATCH 1/5] Make URL case insensitive. Now URL's starting with hTTp or Https will be captured by the regular expression. --- lib/marked.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/marked.js b/lib/marked.js index 51c7c2ac06..4ac240e5c1 100644 --- a/lib/marked.js +++ b/lib/marked.js @@ -606,7 +606,7 @@ inline.pedantic = merge({}, inline.normal, { inline.gfm = merge({}, inline.normal, { escape: edit(inline.escape).replace('])', '~|])').getRegex(), _extended_email: /[A-Za-z0-9._+-]+(@)[a-zA-Z0-9-_]+(?:\.[a-zA-Z0-9-_]*[a-zA-Z0-9])+(?![-_])/, - url: /^((?:ftp|https?):\/\/|www\.)(?:[a-zA-Z0-9\-]+\.?)+[^\s<]*|^email/, + url: /^((?:ftp|https?):\/\/|www\.)(?:[a-zA-Z0-9\-]+\.?)+[^\s<]*|^email/i, _backpedal: /(?:[^?!.,:;*_~()&]+|\([^)]*\)|&(?![a-zA-Z0-9]+;$)|[?!.,:;*_~)]+(?!$))+/, del: /^~+(?=\S)([\s\S]*?\S)~+/, text: edit(inline.text) From 8c855f3c8f9f854e5defd3348c274a87c2fb11c9 Mon Sep 17 00:00:00 2001 From: Roy <40822827+roygold7@users.noreply.github.com> Date: Thu, 4 Oct 2018 15:02:44 +0300 Subject: [PATCH 2/5] Add case insensitive flag to rules.url --- lib/marked.js | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/marked.js b/lib/marked.js index 4ac240e5c1..c212d81b4c 100644 --- a/lib/marked.js +++ b/lib/marked.js @@ -647,6 +647,7 @@ function InlineLexer(links, options) { } else if (this.options.gfm) { if (this.options.breaks) { this.rules = inline.breaks; + this.rules.url = new RegExp(this.rules.url, "i"); } else { this.rules = inline.gfm; } From 3725f9eba3e5fb7855246db32e821f60b45c0d63 Mon Sep 17 00:00:00 2001 From: Roy <40822827+roygold7@users.noreply.github.com> Date: Thu, 4 Oct 2018 16:53:31 +0300 Subject: [PATCH 3/5] Fixed node legacy version --- lib/marked.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/marked.js b/lib/marked.js index c212d81b4c..2d92c063e3 100644 --- a/lib/marked.js +++ b/lib/marked.js @@ -647,7 +647,7 @@ function InlineLexer(links, options) { } else if (this.options.gfm) { if (this.options.breaks) { this.rules = inline.breaks; - this.rules.url = new RegExp(this.rules.url, "i"); + this.rules.url = new RegExp(this.rules.url.source, "i"); } else { this.rules = inline.gfm; } From 408294e8d2b0f72645013774c8c2afdb773d15b6 Mon Sep 17 00:00:00 2001 From: Roy <40822827+roygold7@users.noreply.github.com> Date: Thu, 4 Oct 2018 19:44:25 +0300 Subject: [PATCH 4/5] Changed "i" to 'i' for linter --- lib/marked.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/marked.js b/lib/marked.js index 2d92c063e3..8046be6fb7 100644 --- a/lib/marked.js +++ b/lib/marked.js @@ -647,7 +647,7 @@ function InlineLexer(links, options) { } else if (this.options.gfm) { if (this.options.breaks) { this.rules = inline.breaks; - this.rules.url = new RegExp(this.rules.url.source, "i"); + this.rules.url = new RegExp(this.rules.url.source, 'i'); } else { this.rules = inline.gfm; } From 971304ab0a6c095fc0440a587af3ad43833dabb7 Mon Sep 17 00:00:00 2001 From: Roy <40822827+roygold7@users.noreply.github.com> Date: Thu, 4 Oct 2018 21:02:59 +0300 Subject: [PATCH 5/5] unit test for case insensitivity --- test/unit/marked-spec.js | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/test/unit/marked-spec.js b/test/unit/marked-spec.js index 97789afe09..cdb897488c 100644 --- a/test/unit/marked-spec.js +++ b/test/unit/marked-spec.js @@ -25,3 +25,13 @@ describe('Test paragraph token type', function () { expect(tokens[7].type).toBe('text'); }); }); + +describe('Test url token type', function () { + it('should use the "url" type', function () { + const md = 'HtTps://www.testsite.com'; + + const tokens = marked.lexer(md); + + expect(tokens[0].type).toBe('url'); + }); +});