Relax Language First Line Match (#21586)

* Relax Language First Line Match

Fixes #21533

**Bug**
The first line pattern for a language currently requires the entire line to match. This does is different from how tools such as textmate use firstLineMatch

**Fix**
Relax this restriction so that any match is used

* Fix failing test
This commit is contained in:
Matt Bierner 2017-03-01 18:22:54 -08:00 committed by GitHub
parent 9b91a22918
commit 6b74e23c53
2 changed files with 2 additions and 3 deletions

View file

@ -202,9 +202,8 @@ function guessMimeTypeByFirstline(firstLine: string): string {
continue;
}
// Make sure the entire line matches, not just a subpart.
let matches = firstLine.match(association.firstline);
if (matches && matches.length > 0 && matches[0].length === firstLine.length) {
if (matches && matches.length > 0) {
return association.mime;
}
}

View file

@ -37,7 +37,7 @@ suite('Mime', () => {
guess = guessMimeTypes('Randomfile.noregistration', 'RegexesAreNice');
assert.deepEqual(guess, ['text/nice-regex', 'text/plain']);
guess = guessMimeTypes('Randomfile.noregistration', 'RegexesAreNiceee');
guess = guessMimeTypes('Randomfile.noregistration', 'RegexesAreNotNice');
assert.deepEqual(guess, ['application/unknown']);
guess = guessMimeTypes('Codefile', 'RegexesAreNice');