Use blacklist for puctuators

Currently we can't use `/\p{L}/u` which would let use use a whitelist instead

Fixes #37079
This commit is contained in:
Matt Bierner
2018-05-25 11:56:41 -07:00
parent 281f242cff
commit 558c694d47
2 changed files with 19 additions and 1 deletions

View File

@@ -23,7 +23,7 @@ export const githubSlugifier: Slugifier = new class implements Slugifier {
heading.trim()
.toLowerCase()
.replace(/\s+/g, '-') // Replace whitespace with -
.replace(/[^\w\-]+/gu, '') // Remove non-word chars
.replace(/[\]\[\!\'\#\$\%\&\'\(\)\*\+\,\.\/\:\;\<\=\>\?\@\\\^\_\{\|\}\~\`]/g, '') // Remove known puctuators
.replace(/^\-+/, '') // Remove leading -
.replace(/\-+$/, '') // Remove trailing -
);

View File

@@ -88,4 +88,22 @@ suite('markdown.TableOfContentsProvider', () => {
assert.strictEqual((await provider.lookup('инструкция---делай-раз-делай-два'))!.line, 0);
});
test('should handle special characters 3, #37079', async () => {
const doc = new InMemoryDocument(testFileName, `## Header 2
### Header 3
## Заголовок 2
### Заголовок 3
### Заголовок Header 3
## Заголовок`);
const provider = new TableOfContentsProvider(createNewMarkdownEngine(), doc);
assert.strictEqual((await provider.lookup('header-2'))!.line, 0);
assert.strictEqual((await provider.lookup('header-3'))!.line, 1);
assert.strictEqual((await provider.lookup('Заголовок-2'))!.line, 2);
assert.strictEqual((await provider.lookup('Заголовок-3'))!.line, 3);
assert.strictEqual((await provider.lookup('Заголовок-header-3'))!.line, 4);
assert.strictEqual((await provider.lookup('Заголовок'))!.line, 5);
});
});