]> git.proxmox.com Git - mirror_novnc.git/blobdiff - core/util/strings.js
Build in the behavior to ignore decodeUTF8 errors
[mirror_novnc.git] / core / util / strings.js
index 944e81c8d0555716a2a43ba62caca99a32b3642f..3dd4b29fb023968aa41c36bc0d14c402909553ee 100644 (file)
@@ -7,8 +7,19 @@
  */
 
 // Decode from UTF-8
-export function decodeUTF8(utf8string) {
-    return decodeURIComponent(escape(utf8string));
+export function decodeUTF8(utf8string, allowLatin1=false) {
+    try {
+        return decodeURIComponent(escape(utf8string));
+    } catch (e) {
+        if (e instanceof URIError) {
+            if (allowLatin1) {
+                // If we allow Latin1 we can ignore any decoding fails
+                // and in these cases return the original string
+                return utf8string;
+            }
+        }
+        throw e;
+    }
 }
 
 // Encode to UTF-8