From 3d90c8a8c238270cabbc4ec49c43842d30c2cb0f Mon Sep 17 00:00:00 2001 From: Jeff Williams Date: Thu, 16 Feb 2023 08:20:13 -0800 Subject: [PATCH] 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`. --- lib/jsdoc/util/templateHelper.js | 7 +++++++ test/specs/jsdoc/util/templateHelper.js | 7 +++++++ 2 files changed, 14 insertions(+) diff --git a/lib/jsdoc/util/templateHelper.js b/lib/jsdoc/util/templateHelper.js index fa1604f2..1b967ba5 100644 --- a/lib/jsdoc/util/templateHelper.js +++ b/lib/jsdoc/util/templateHelper.js @@ -425,6 +425,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/test/specs/jsdoc/util/templateHelper.js b/test/specs/jsdoc/util/templateHelper.js index bd6d2d9b..aac38dde 100644 --- a/test/specs/jsdoc/util/templateHelper.js +++ b/test/specs/jsdoc/util/templateHelper.js @@ -1517,6 +1517,13 @@ describe("jsdoc/util/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); + + 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);