Skip to content

Commit ae27cd2

Browse files
authored
fix(normalize-see-links): minimally escape link targets instead of encodeURI (#1735)
1 parent cfe9cdb commit ae27cd2

2 files changed

Lines changed: 45 additions & 1 deletion

File tree

‎src/rules/normalizeSeeLinks.js‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,11 @@ const escapeLinkLabel = (canonicalForm, label, sourceForm) => {
4747
* @returns {string}
4848
*/
4949
const encodeLinkTarget = (target) => {
50-
return encodeURI(target).replaceAll(/%25(?=[\dA-F]{2})/giv, '%');
50+
return target
51+
.replaceAll(/%(?![\dA-F]{2})/giv, '%25')
52+
.replaceAll('|', '%7C')
53+
.replaceAll('{', '%7B')
54+
.replaceAll('}', '%7D');
5155
};
5256

5357
/**

‎test/rules/assertions/normalizeSeeLinks.js‎

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,46 @@ export default {
2222
*/
2323
`,
2424
},
25+
{
26+
code: `
27+
/**
28+
* @see [Unicode](https://example.com/päth)
29+
*/
30+
`,
31+
errors: [
32+
{
33+
line: 3,
34+
message: 'Expected @see link to use the pipe form.',
35+
},
36+
],
37+
ignoreReadme: true,
38+
name: 'preserves non-ASCII characters in link targets',
39+
output: `
40+
/**
41+
* @see {@link https://example.com/päth|Unicode}
42+
*/
43+
`,
44+
},
45+
{
46+
code: `
47+
/**
48+
* @see [Caret](https://example.com/a^b)
49+
*/
50+
`,
51+
errors: [
52+
{
53+
line: 3,
54+
message: 'Expected @see link to use the pipe form.',
55+
},
56+
],
57+
ignoreReadme: true,
58+
name: 'preserves encodeURI-only ASCII characters in link targets',
59+
output: `
60+
/**
61+
* @see {@link https://example.com/a^b|Caret}
62+
*/
63+
`,
64+
},
2565
// jsdoccomment 0.89 and later round-trip an escaped pipe-label delimiter.
2666
{
2767
code: `

0 commit comments

Comments
 (0)