
Previously, our auto-linking feature would match `http` in URLs (such as `http://...`) to the `common/http` package and automatically create a link to that, which was undesirable. While it is possible to work around that via `<code class="no-auto-link">http://...</code>`, most people didn't even realize the issue. Since in this case it is possible to reliably know it is a false match, this commit fixes it by applying a custom auto-link filter that ignores all docs for `http`, if it comes before `://`. Fixes #31012 PR Close #31051
50 lines
2.0 KiB
JavaScript
50 lines
2.0 KiB
JavaScript
const ignoreHttpInUrls = require('./ignoreHttpInUrls')();
|
|
|
|
describe('ignoreHttpInUrls', () => {
|
|
it('should ignore all docs when matching `http` in `http://...`', () => {
|
|
const docs = [{ docType: 'package', name: 'http' }, { docType: 'class', name: 'Foo' }];
|
|
|
|
const words1 = ['http', '://', 'example', '.', 'com', '/'];
|
|
expect(ignoreHttpInUrls(docs, words1, 0)).toEqual([]);
|
|
|
|
const words2 = ['URL', ': ', 'http', '://', 'example', '.', 'com', '/'];
|
|
expect(ignoreHttpInUrls(docs, words2, 2)).toEqual([]);
|
|
});
|
|
|
|
it('should ignore all docs when matching `https` in `https://...`', () => {
|
|
const docs = [{ docType: 'package', name: 'https' }, { docType: 'class', name: 'Foo' }];
|
|
|
|
const words1 = ['https', '://', 'example', '.', 'com', '/'];
|
|
expect(ignoreHttpInUrls(docs, words1, 0)).toEqual([]);
|
|
|
|
const words2 = ['URL', ': ', 'https', '://', 'example', '.', 'com', '/'];
|
|
expect(ignoreHttpInUrls(docs, words2, 2)).toEqual([]);
|
|
});
|
|
|
|
it('should keep all docs when not matching `http(s)`', () => {
|
|
const docs = [{ docType: 'package', name: 'http' }, { docType: 'class', name: 'Foo' }];
|
|
|
|
const words1 = ['http', '://', 'example', '.', 'com', '/'];
|
|
expect(ignoreHttpInUrls(docs, words1, 2)).toEqual(docs);
|
|
|
|
const words2 = ['URL', ': ', 'https', '://', 'example', '.', 'com', '/'];
|
|
expect(ignoreHttpInUrls(docs, words2, 0)).toEqual(docs);
|
|
|
|
const words3 = ['file', '://', 'example', '.', 'com', '/'];
|
|
expect(ignoreHttpInUrls(docs, words3, 0)).toEqual(docs);
|
|
});
|
|
|
|
it('should keep all docs when not matching `http(s)` at the beginning of a URL', () => {
|
|
const docs = [{ docType: 'package', name: 'http' }, { docType: 'class', name: 'Foo' }];
|
|
|
|
const words1 = ['http', ' ', 'is', ' ', 'cool'];
|
|
expect(ignoreHttpInUrls(docs, words1, 0)).toEqual(docs);
|
|
|
|
const words2 = ['https', ' ', 'is', ' ', 'cooler'];
|
|
expect(ignoreHttpInUrls(docs, words2, 0)).toEqual(docs);
|
|
|
|
const words3 = ['http', '://', 'http', '.', 'com'];
|
|
expect(ignoreHttpInUrls(docs, words3, 2)).toEqual(docs);
|
|
});
|
|
});
|