Skip to content

Commit

Permalink
Relax Language First Line Match (#21586)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
mjbvz authored Mar 2, 2017
1 parent 9b91a22 commit 6b74e23
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 3 deletions.
3 changes: 1 addition & 2 deletions src/vs/base/common/mime.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/vs/base/test/common/mime.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down

0 comments on commit 6b74e23

Please sign in to comment.