Skip to content

Commit

Permalink
Support XML encoding with UTF-8 including BOM field (#491)
Browse files Browse the repository at this point in the history
  • Loading branch information
Borewit committed Sep 17, 2021
1 parent 74c852b commit 8bca6b4
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 0 deletions.
7 changes: 7 additions & 0 deletions core.js
Expand Up @@ -1066,6 +1066,13 @@ async function _fromTokenizer(tokenizer) {
};
}

if (check([0xEF, 0xBB, 0xBF]) && checkString('<?xml', {offset: 3})) { // UTF-8-BOM
return {
ext: 'xml',
mime: 'application/xml',
};
}

// -- 9-byte signatures --

if (check([0x49, 0x49, 0x52, 0x4F, 0x08, 0x00, 0x00, 0x00, 0x18])) {
Expand Down
4 changes: 4 additions & 0 deletions fixture/fixture-utf8-bom.xml
@@ -0,0 +1,4 @@
<?xml version="1.0" encoding="UTF-16"?>
<FileType>
<encoding>UTF-8 with BOM</encoding>
</FileType>
4 changes: 4 additions & 0 deletions test.js
Expand Up @@ -206,6 +206,10 @@ const names = {
webm: [
'fixture-null', // EBML DocType with trailing null character
],
xml: [
'fixture',
'fixture-utf8-bom', // UTF-8 with BOM
],
};

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

0 comments on commit 8bca6b4

Please sign in to comment.