Skip to content

Commit 50440f2

Browse files
committed
Add unit test for bad characters in the displayText
1 parent 487665e commit 50440f2

2 files changed

Lines changed: 20 additions & 2 deletions

File tree

‎libraries/api-extractor/src/DocElementParser.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ export default class DocElementParser {
199199
if (displayTextPart) {
200200
const match: RegExpExecArray | undefined = this._displayTextBadCharacterRegEx.exec(displayTextPart);
201201
if (match) {
202-
documentation.reportError(`The {@link} tag\'s display text contains an unsupported `
202+
documentation.reportError(`The {@link} tag\'s display text contains an unsupported`
203203
+ ` character: "${match[0]}"`);
204204
return undefined;
205205
}

‎libraries/api-extractor/src/test/DocElementParser.test.ts‎

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -284,7 +284,25 @@ describe('DocElementParser tests', function (): void {
284284
+ ' contains spaces, encode them using %20; for display text, use a pipe delimiter ("|")']);
285285
});
286286

287-
it('Should parse @link with API defintion reference', (): void => {
287+
it('Should reject @link with bad display text character', (): void => {
288+
clearCapturedErrors();
289+
290+
const docs: string = '{@link https://example.com | Ex@ample}';
291+
const tokenizer: Tokenizer = new Tokenizer(docs, console.log);
292+
293+
let docElements: IDocElement[];
294+
/* tslint:disable-next-line:no-any */
295+
let errorMessage: any;
296+
try {
297+
docElements = DocElementParser.parse(myDocumentedClass.documentation, tokenizer);
298+
} catch (error) {
299+
errorMessage = error;
300+
}
301+
assert.isUndefined(errorMessage);
302+
assertCapturedErrors(['The {@link} tag\'s display text contains an unsupported character: "@"']);
303+
});
304+
305+
it('Should parse @link with API definition reference', (): void => {
288306
clearCapturedErrors();
289307
const docs: string = '{@link @microsoft/sp-core-library:Guid.equals}';
290308
const tokenizer: Tokenizer = new Tokenizer(docs, console.log);

0 commit comments

Comments
 (0)