encode as mdn tells me to

This commit is contained in:
Roberto Hidalgo 2023-01-04 14:04:37 -06:00
parent c6af2c8a98
commit 08f9671aaf

View File

@ -3,7 +3,7 @@
import * as webauthnJSON from 'https://unpkg.com/@github/webauthn-json@2.0.2/dist/esm/webauthn-json.browser-ponyfill.js' import * as webauthnJSON from 'https://unpkg.com/@github/webauthn-json@2.0.2/dist/esm/webauthn-json.browser-ponyfill.js'
const charsToEncode = /[\u007f-\uffff]/g; const charsToEncode = /[\u007f-\uffff]/g;
function JSONtob64(data) { function JSONtob64(data) {
return btoa(JSON.stringify(data).replace(charsToEncode, (c) => '\\u'+('000'+c.charCodeAt(0).toString(16)).slice(-4))) return btoa(encodeURIComponent(JSON.stringify(data).replace(charsToEncode, (c) => '\\u'+('000'+c.charCodeAt(0).toString(16)).slice(-4))))
} }
function b64ToJSON(encoded) { function b64ToJSON(encoded) {