Skip to content

Commit

Permalink
Anchor links are not relative links
Browse files Browse the repository at this point in the history
Resolves #2604
  • Loading branch information
Gerrit0 committed Jun 22, 2024
1 parent 41f0040 commit c528c0a
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 5 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
### Bug Fixes

- Added `@author` to the default list of recognized tags, #2603.
- Anchor links are no longer incorrectly checked for relative paths, #2604

### Thanks!

Expand Down
2 changes: 1 addition & 1 deletion src/lib/converter/comments/textParser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ function checkAttribute(
}

function isRelativeLink(link: string) {
return !/^[a-z]+:\/\/|^\/|^[a-z]:\\/i.test(link);
return !/^[a-z]+:\/\/|^\/|^[a-z]:\\|^#/i.test(link);
}

function findLabelEnd(text: string, pos: number) {
Expand Down
10 changes: 6 additions & 4 deletions src/test/comments.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1356,7 +1356,7 @@ describe("Comment Parser", () => {
it("Recognizes markdown links", () => {
const comment = getComment(`/**
* [text](./relative.md) ![](image.png)
* Not relative: [passwd](/etc/passwd) [Windows](C:\\\\\\\\Windows) [example.com](http://example.com)
* Not relative: [passwd](/etc/passwd) [Windows](C:\\\\\\\\Windows) [example.com](http://example.com) [hash](#hash)
*/`);

equal(comment.summary, [
Expand All @@ -1366,7 +1366,7 @@ describe("Comment Parser", () => {
{ kind: "relative-link", text: "image.png", target: 2 },
{
kind: "text",
text: ")\nNot relative: [passwd](/etc/passwd) [Windows](C:\\\\\\\\Windows) [example.com](http://example.com)",
text: ")\nNot relative: [passwd](/etc/passwd) [Windows](C:\\\\\\\\Windows) [example.com](http://example.com) [hash](#hash)",
},
] satisfies CommentDisplayPart[]);
});
Expand All @@ -1376,6 +1376,7 @@ describe("Comment Parser", () => {
* [1]: ./example.md
* [2]:<./example with space>
* [3]: https://example.com
* [4]: #hash
*/`);

equal(comment.summary, [
Expand All @@ -1389,7 +1390,7 @@ describe("Comment Parser", () => {
},
{
kind: "text",
text: "\n[3]: https://example.com",
text: "\n[3]: https://example.com\n[4]: #hash",
},
] satisfies CommentDisplayPart[]);
});
Expand Down Expand Up @@ -1422,6 +1423,7 @@ describe("Comment Parser", () => {
* <a data-foo="./path.txt" href="./test.png" >
* <a href="./test space.png"/>
* <a href="https://example.com/favicon.ico">
* <a href="#hash">
*/`);

equal(comment.summary, [
Expand All @@ -1435,7 +1437,7 @@ describe("Comment Parser", () => {
},
{
kind: "text",
text: '"/>\n<a href="https://example.com/favicon.ico">',
text: '"/>\n<a href="https://example.com/favicon.ico">\n<a href="#hash">',
},
] satisfies CommentDisplayPart[]);
});
Expand Down

0 comments on commit c528c0a

Please sign in to comment.