-
Notifications
You must be signed in to change notification settings - Fork 709
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Resolves #2613
- Loading branch information
Showing
3 changed files
with
23 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -189,7 +189,7 @@ function checkMarkdownLink( | |
if (link.ok) { | ||
// Only make a relative-link display part if it's actually a relative link. | ||
// Discard protocol:// links, unix style absolute paths, and windows style absolute paths. | ||
if (isRelativeLink(link.str)) { | ||
if (isRelativePath(link.str)) { | ||
return { | ||
pos: labelEnd + 2, | ||
end: link.pos, | ||
|
@@ -240,7 +240,7 @@ function checkReference(data: TextParserData): RelativeLink | undefined { | |
); | ||
|
||
if (link.ok) { | ||
if (isRelativeLink(link.str)) { | ||
if (isRelativePath(link.str)) { | ||
return { | ||
pos: lookahead, | ||
end: link.pos, | ||
|
@@ -284,7 +284,7 @@ function checkAttribute( | |
) { | ||
parser.step(); | ||
|
||
if (isRelativeLink(parser.currentAttributeValue)) { | ||
if (isRelativePath(parser.currentAttributeValue)) { | ||
data.pos = parser.pos; | ||
return { | ||
pos: parser.currentAttributeValueStart, | ||
|
@@ -302,8 +302,14 @@ function checkAttribute( | |
} | ||
} | ||
|
||
function isRelativeLink(link: string) { | ||
return !/^[a-z]+:\/\/|^\/|^[a-z]:\\|^#/i.test(link); | ||
function isRelativePath(link: string) { | ||
// Lots of edge cases encoded right here! | ||
// Originally, this attempted to match protocol://, but... | ||
// `mailto:[email protected]` is not a relative path | ||
// `C:\foo` is not a relative path | ||
// `/etc/passwd` is not a relative path | ||
// `#anchor` is not a relative path | ||
return !/^[a-z]+:|^\/|^#/i.test(link); | ||
} | ||
|
||
function findLabelEnd(text: string, pos: number) { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1447,6 +1447,16 @@ describe("Comment Parser", () => { | |
] satisfies CommentDisplayPart[]); | ||
}); | ||
|
||
it("Does not mistake mailto: links as relative paths", () => { | ||
const comment = getComment(`/** | ||
* [1]: mailto:[email protected] | ||
*/`); | ||
|
||
equal(comment.summary, [ | ||
{ kind: "text", text: "[1]: mailto:[email protected]" }, | ||
] satisfies CommentDisplayPart[]); | ||
}); | ||
|
||
it("Recognizes HTML image links", () => { | ||
const comment = getComment(`/** | ||
* <img width=100 height="200" src="./test.png" > | ||
|