Skip to content

Commit

Permalink
Detect XML UTF-16-BE & UTF-16-LE via pattern matching
Browse files Browse the repository at this point in the history
  • Loading branch information
Borewit committed Sep 14, 2021
1 parent 74c852b commit b6e0319
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 0 deletions.
9 changes: 9 additions & 0 deletions core.js
Expand Up @@ -1203,6 +1203,15 @@ async function _fromTokenizer(tokenizer) {
};
}

if (check([0xFE, 0xFF, 0, 60, 0, 63, 0, 120, 0, 109, 0, 108]) // UTF-16-BOM-LE
|| check([0xFF, 0xFE, 60, 0, 63, 0, 120, 0, 109, 0, 108, 0])
) { // UTF-16-BOM-LE
return {
ext: 'xml',
mime: 'application/xml',
};
}

// -- Unsafe signatures --

if (
Expand Down
Binary file added fixture/fixture-utf16-be-bom.xml
Binary file not shown.
Binary file added fixture/fixture-utf16-le-bom.xml
Binary file not shown.
5 changes: 5 additions & 0 deletions test.js
Expand Up @@ -206,6 +206,11 @@ const names = {
webm: [
'fixture-null', // EBML DocType with trailing null character
],
xml: [
'fixture',
'fixture-utf16-be-bom', // UTF-16 little endian encoded XML, with BOM
'fixture-utf16-le-bom', // UTF-16 big endian encoded XML, with BOM
],
};

// Define an entry here only if the file type has potential
Expand Down

0 comments on commit b6e0319

Please sign in to comment.