File tree 3 files changed +23
-3
lines changed
apps/api-documenter/src/documenters
build-tests/api-documenter-test/etc/yaml/api-documenter-test
common/changes/@microsoft/api-documenter
3 files changed +23
-3
lines changed Original file line number Diff line number Diff line change @@ -666,7 +666,16 @@ export class YamlDocumenter {
666
666
onGetFilenameForApiItem : ( apiItem : ApiItem ) => {
667
667
// NOTE: GitHub's markdown renderer does not resolve relative hyperlinks correctly
668
668
// unless they start with "./" or "../".
669
- return `xref:${ this . _getUid ( apiItem ) } ` ;
669
+
670
+ // To ensure the xref is properly escaped, we first encode the entire xref
671
+ // to handle escaping of reserved characters. Then we must replace '#' and '?'
672
+ // characters so that they are not interpreted as a querystring or hash.
673
+ // We must also backslash-escape unbalanced `(` and `)` characters as the
674
+ // markdown spec insists that they are only valid when balanced. To reduce
675
+ // the overhead we only support balanced parenthesis with a depth of 1.
676
+ return encodeURI ( `xref:${ this . _getUid ( apiItem ) } ` )
677
+ . replace ( / [ # ? ] / g, s => encodeURIComponent ( s ) )
678
+ . replace ( / ( \( [ ^ ( ] * \) ) | [ ( ) ] / g, ( s , balanced ) => balanced || ( '\\' + s ) ) ;
670
679
}
671
680
} ) ;
672
681
Original file line number Diff line number Diff line change 3
3
- uid : ' api-documenter-test!DocClass1:class'
4
4
summary : This is an example class.
5
5
remarks : >-
6
- [Link to overload 1](xref:api-documenter-test!DocClass1#exampleFunction :member(1))
6
+ [Link to overload 1](xref:api-documenter-test!DocClass1%23exampleFunction :member(1))
7
7
8
8
9
- [Link to overload 2](xref:api-documenter-test!DocClass1#exampleFunction :member(2))
9
+ [Link to overload 2](xref:api-documenter-test!DocClass1%23exampleFunction :member(2))
10
10
11
11
12
12
Original file line number Diff line number Diff line change
1
+ {
2
+ "changes" : [
3
+ {
4
+ "packageName" : " @microsoft/api-documenter" ,
5
+ "comment" : " Properly encode xrefs that contain '#' characters." ,
6
+ "type" : " patch"
7
+ }
8
+ ],
9
+ "packageName" : " @microsoft/api-documenter" ,
10
+ "email" : " ron.buckton@microsoft.com"
11
+ }
You can’t perform that action at this time.
0 commit comments