@preference-sl/pref-viewer 2.11.0-beta.17 → 2.11.0-beta.18
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/src/svg-resolver.js +23 -0
package/package.json
CHANGED
package/src/svg-resolver.js
CHANGED
|
@@ -121,6 +121,29 @@ export default class SVGResolver {
|
|
|
121
121
|
return [value, size];
|
|
122
122
|
}
|
|
123
123
|
|
|
124
|
+
// Some payloads are base64 of UTF-16 strings, which leave NUL bytes after atob; strip them and retry.
|
|
125
|
+
const cleanedDecoded = decoded.replace(/\u0000/g, "");
|
|
126
|
+
if (cleanedDecoded !== decoded && isSvg(cleanedDecoded)) {
|
|
127
|
+
size = raw.length;
|
|
128
|
+
value = cleanedDecoded;
|
|
129
|
+
return [value, size];
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
// Last resort: attempt decoding the binary buffer as UTF-16LE when available (TextDecoder is native in browsers).
|
|
133
|
+
if (typeof TextDecoder !== "undefined") {
|
|
134
|
+
try {
|
|
135
|
+
const bytes = Uint8Array.from(decoded, (c) => c.charCodeAt(0));
|
|
136
|
+
const utf16 = new TextDecoder("utf-16le").decode(bytes);
|
|
137
|
+
if (isSvg(utf16)) {
|
|
138
|
+
size = raw.length;
|
|
139
|
+
value = utf16;
|
|
140
|
+
return [value, size];
|
|
141
|
+
}
|
|
142
|
+
} catch {
|
|
143
|
+
// ignore and fall through
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
|
|
124
147
|
return [value, size];
|
|
125
148
|
}
|
|
126
149
|
|