fix(jsdoc-template-legacy): 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`.

Ported from 3d90c8a8c2.
This commit is contained in:
Jeff Williams 2023-02-18 15:23:09 -08:00
parent aa529d9a33
commit 67d043160f
No known key found for this signature in database
2 changed files with 14 additions and 0 deletions

View File

@ -419,6 +419,13 @@ function splitLinkText(text) {
target = text.substr(0, splitIndex); target = text.substr(0, splitIndex);
} }
if (linkText) {
linkText = linkText.trim();
}
if (target) {
target = target.trim();
}
return { return {
linkText: linkText, linkText: linkText,
target: target || text, target: target || text,

View File

@ -1396,6 +1396,13 @@ describe('@jsdoc/template-legacy/lib/templateHelper', () => {
expect(output).toBe('Link to <a href="path/to/test.html">Test</a>'); expect(output).toBe('Link to <a href="path/to/test.html">Test</a>');
}); });
it('should not add spaces to the href or text when there are spaces around the pipe', () => {
const input = 'Link to {@link test | Test}';
const output = helper.resolveLinks(input, jsdoc.deps);
expect(output).toBe('Link to <a href="path/to/test.html">Test</a>');
});
it('should allow first space to be used as delimiter between href and text (external link)', () => { it('should allow first space to be used as delimiter between href and text (external link)', () => {
const input = 'Link to {@link http://github.com Github}'; const input = 'Link to {@link http://github.com Github}';
const output = helper.resolveLinks(input, jsdoc.deps); const output = helper.resolveLinks(input, jsdoc.deps);