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

Fix trailing periods for naked URLs #1175

Merged
merged 1 commit into from
Dec 14, 2024
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
23 changes: 23 additions & 0 deletions common/markdown_parser/parser.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -216,3 +216,26 @@ Deno.test("Test hashtag helper functions", () => {
// should behave like this for all characters in tagRegex
assertEquals(renderHashtag("exclamation!"), "#<exclamation!>");
});

const nakedURLSample = `
http://abc.com is a URL
Also http://no-trailing-period.com. That's a URL. It ends with m, not '.'.
http://no-trailing-comma.com, that same a URL, ends with m (and not ',').
http://trailing-slash.com/. That ends with '/' (still not '.').
http://abc.com?e=2.71,pi=3.14 is a URL too.
http://abc.com?e=2.71. That is a URL, which ends with 1 (and not '.').
`;

Deno.test("Test NakedURL parser", () => {
const tree = parseMarkdown(nakedURLSample);
const urls = collectNodesOfType(tree, "NakedURL");

assertEquals(urls.map((x) => x.children![0].text), [
"http://abc.com",
"http://no-trailing-period.com",
"http://no-trailing-comma.com",
"http://trailing-slash.com/",
"http://abc.com?e=2.71,pi=3.14",
"http://abc.com?e=2.71",
]);
});
2 changes: 1 addition & 1 deletion common/markdown_parser/parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -577,7 +577,7 @@ const NakedURL = regexParser(
{
firstCharCode: 104, // h
regex:
/^https?:\/\/[-a-zA-Z0-9@:%._\+~#=,;]{1,256}([-a-zA-Z0-9()@:%_\+.,;~#?&=\/]*)/,
/(^https?:\/\/([-a-zA-Z0-9@:%_\+~#=]|(?:[.](?!(\s|$)))){1,256})(([-a-zA-Z0-9(@:%_\+~#?&=\/]|(?:[.,:;)](?!(\s|$))))*)/,
nodeType: "NakedURL",
className: "sb-naked-url",
tag: NakedURLTag,
Expand Down
Loading