From 697ac2a42e5b90e2cecc82067638f2e3c82c0010 Mon Sep 17 00:00:00 2001
From: Tony Brix
Date: Wed, 7 Dec 2022 01:44:55 -0600
Subject: [PATCH] fix: remove quotes at the end of gfm autolink (#2673)
Fixes undefined
---
src/Tokenizer.js | 4 ++--
src/rules.js | 2 +-
test/specs/new/autolinks_quotes.html | 3 +++
test/specs/new/autolinks_quotes.md | 3 +++
4 files changed, 9 insertions(+), 3 deletions(-)
create mode 100644 test/specs/new/autolinks_quotes.html
create mode 100644 test/specs/new/autolinks_quotes.md
diff --git a/src/Tokenizer.js b/src/Tokenizer.js
index ad7ac4010b..bf9dc88404 100644
--- a/src/Tokenizer.js
+++ b/src/Tokenizer.js
@@ -733,9 +733,9 @@ export class Tokenizer {
} while (prevCapZero !== cap[0]);
text = escape(cap[0]);
if (cap[1] === 'www.') {
- href = 'http://' + text;
+ href = 'http://' + cap[0];
} else {
- href = text;
+ href = cap[0];
}
}
return {
diff --git a/src/rules.js b/src/rules.js
index 6b29dfd0b0..b53eb347cd 100644
--- a/src/rules.js
+++ b/src/rules.js
@@ -284,7 +284,7 @@ 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/,
- _backpedal: /(?:[^?!.,:;*_~()&]+|\([^)]*\)|&(?![a-zA-Z0-9]+;$)|[?!.,:;*_~)]+(?!$))+/,
+ _backpedal: /(?:[^?!.,:;*_'"~()&]+|\([^)]*\)|&(?![a-zA-Z0-9]+;$)|[?!.,:;*_'"~)]+(?!$))+/,
del: /^(~~?)(?=[^\s~])([\s\S]*?[^\s~])\1(?=[^~]|$)/,
text: /^([`~]+|[^`~])(?:(?= {2,}\n)|(?=[a-zA-Z0-9.!#$%&'*+\/=?_`{\|}~-]+@)|[\s\S]*?(?:(?=[\\"https://www.example.com?test=quote-in-"-url"
+
+'https://www.example.com?test=quote-in-'-url'
diff --git a/test/specs/new/autolinks_quotes.md b/test/specs/new/autolinks_quotes.md
new file mode 100644
index 0000000000..c3fb4d2b7d
--- /dev/null
+++ b/test/specs/new/autolinks_quotes.md
@@ -0,0 +1,3 @@
+"https://www.example.com?test=quote-in-"-url"
+
+'https://www.example.com?test=quote-in-'-url'