From 67d043160fead32d8ffdcd28ef5cf9ec50bac92c Mon Sep 17 00:00:00 2001 From: Jeff Williams Date: Sat, 18 Feb 2023 15:23:09 -0800 Subject: [PATCH] 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 https://github.com/jsdoc/jsdoc/commit/3d90c8a8c238270cabbc4ec49c43842d30c2cb0f. --- packages/jsdoc-template-legacy/lib/templateHelper.js | 7 +++++++ .../jsdoc-template-legacy/test/specs/lib/templateHelper.js | 7 +++++++ 2 files changed, 14 insertions(+) diff --git a/packages/jsdoc-template-legacy/lib/templateHelper.js b/packages/jsdoc-template-legacy/lib/templateHelper.js index caa36724..db48852c 100644 --- a/packages/jsdoc-template-legacy/lib/templateHelper.js +++ b/packages/jsdoc-template-legacy/lib/templateHelper.js @@ -419,6 +419,13 @@ function splitLinkText(text) { target = text.substr(0, splitIndex); } + if (linkText) { + linkText = linkText.trim(); + } + if (target) { + target = target.trim(); + } + return { linkText: linkText, target: target || text, diff --git a/packages/jsdoc-template-legacy/test/specs/lib/templateHelper.js b/packages/jsdoc-template-legacy/test/specs/lib/templateHelper.js index 52b42508..eb33ba01 100644 --- a/packages/jsdoc-template-legacy/test/specs/lib/templateHelper.js +++ b/packages/jsdoc-template-legacy/test/specs/lib/templateHelper.js @@ -1396,6 +1396,13 @@ describe('@jsdoc/template-legacy/lib/templateHelper', () => { expect(output).toBe('Link to Test'); }); + 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 Test'); + }); + 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 output = helper.resolveLinks(input, jsdoc.deps);