@qoniai/qoni 0.4.2 → 0.4.3
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/CHANGELOG.md +10 -0
- package/README.md +2 -0
- package/README.zh-CN.md +2 -0
- package/dist/index.cjs +8 -2
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +8 -2
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -349,8 +349,14 @@ function decodeDataUri(uri) {
|
|
|
349
349
|
const match = /^data:([^;,]*)?(;base64)?,(.*)$/s.exec(uri);
|
|
350
350
|
if (!match) return void 0;
|
|
351
351
|
const [, mime, isBase64, body] = match;
|
|
352
|
-
const
|
|
353
|
-
|
|
352
|
+
const encoded = isBase64 ? body.replace(/\s/g, "") : body;
|
|
353
|
+
if (isBase64 && (!/^[A-Za-z0-9+/_-]+={0,2}$/.test(encoded) || encoded.length % 4 === 1 || encoded.includes("=") && encoded.length % 4 !== 0)) return void 0;
|
|
354
|
+
try {
|
|
355
|
+
const bytes = isBase64 ? new Uint8Array(Buffer.from(encoded, "base64")) : new TextEncoder().encode(decodeURIComponent(encoded));
|
|
356
|
+
return bytes.length ? { bytes, mime: mime || "application/octet-stream" } : void 0;
|
|
357
|
+
} catch {
|
|
358
|
+
return void 0;
|
|
359
|
+
}
|
|
354
360
|
}
|
|
355
361
|
function asString(value) {
|
|
356
362
|
return typeof value === "string" && value ? value : void 0;
|