Skip to content

Commit 3d90c8a

Browse files
committed
fix: in inline links, strip spaces around pipe character
Previously, if you had an inline link tag like `{@link https://example.com/ | link text}`, then the link URL ended up being `https://example.com/%20`.
1 parent 37fc8cd commit 3d90c8a

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

lib/jsdoc/util/templateHelper.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -425,6 +425,13 @@ function splitLinkText(text) {
425425
target = text.substr(0, splitIndex);
426426
}
427427

428+
if (linkText) {
429+
linkText = linkText.trim();
430+
}
431+
if (target) {
432+
target = target.trim();
433+
}
434+
428435
return {
429436
linkText: linkText,
430437
target: target || text

test/specs/jsdoc/util/templateHelper.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1517,6 +1517,13 @@ describe("jsdoc/util/templateHelper", () => {
15171517
expect(output).toBe('Link to <a href="path/to/test.html">Test</a>');
15181518
});
15191519

1520+
it('should not add spaces to the href or text when there are spaces around the pipe', () => {
1521+
const input = 'Link to {@link test | Test}';
1522+
const output = helper.resolveLinks(input);
1523+
1524+
expect(output).toBe('Link to <a href="path/to/test.html">Test</a>');
1525+
});
1526+
15201527
it('should allow first space to be used as delimiter between href and text (external link)', () => {
15211528
const input = 'Link to {@link http://github.com Github}';
15221529
const output = helper.resolveLinks(input);

0 commit comments

Comments
 (0)