Skip to content

Commit

Permalink
Detect XML UTF-16-BE & UTF-16-LE via pattern matching (#490)
Browse files Browse the repository at this point in the history
  • Loading branch information
Borewit committed Sep 17, 2021
1 parent 8bca6b4 commit a2cf2b3
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 0 deletions.
10 changes: 10 additions & 0 deletions core.js
Expand Up @@ -1210,6 +1210,16 @@ 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.
2 changes: 2 additions & 0 deletions test.js
Expand Up @@ -209,6 +209,8 @@ const names = {
xml: [
'fixture',
'fixture-utf8-bom', // UTF-8 with BOM
'fixture-utf16-be-bom', // UTF-16 little endian encoded XML, with BOM
'fixture-utf16-le-bom', // UTF-16 big endian encoded XML, with BOM
],
};

Expand Down

0 comments on commit a2cf2b3

Please sign in to comment.