瀏覽代碼

Fixed invalid xml file due to UTF-BOM for firefox. Fixes issue #242

Benjamin Giesinger 7 年之前
父節點
當前提交
6b44f3ed96
共有 1 個文件被更改,包括 6 次插入1 次删除
  1. 6 1
      src/OpenSheetMusicDisplay/OpenSheetMusicDisplay.ts

+ 6 - 1
src/OpenSheetMusicDisplay/OpenSheetMusicDisplay.ts

@@ -85,10 +85,15 @@ export class OpenSheetMusicDisplay {
                     }
                 );
             }
+            // Javascript loads strings as utf-16, which is wonderful BS if you want to parse UTF-8 :S
+            if (str.substr(0, 3) === "\uf7ef\uf7bb\uf7bf") {
+                // UTF with BOM detected, truncate first three bytes and pass along
+                return self.load(str.substr(3));
+            }
             if (str.substr(0, 5) === "<?xml") {
                 // Parse the string representing an xml file
                 const parser: DOMParser = new DOMParser();
-                content = parser.parseFromString(str, "text/xml");
+                content = parser.parseFromString(str, "application/xml");
             } else if (str.length < 2083) {
                 // Assume now "str" is a URL
                 // Retrieve the file at the given URL