uriencode API qrcode query parameters

This commit is contained in:
Aljaž S
2022-07-06 23:24:26 +02:00
parent 6dd11acaa9
commit 552266bca6
2 changed files with 4 additions and 6 deletions

View File

@@ -102,7 +102,7 @@ section div {
</div>
</section>
<script>
function val (name) { return document.getElementsByName(name)?.[0]?.value || "" }
function val (name) { return encodeURIComponent(document.getElementsByName(name)?.[0]?.value) || "" }
function getNewUrl () {
const qstring = [
["client_name", val("client-name")],
@@ -117,7 +117,7 @@ function getNewUrl () {
["issuer_address", val("issuer-address")],
["issuer_city", val("issuer-city")],
].map(v => `${v[0]}=${v[1]}`).join("&")
return `${window.location.origin}/api/qrcode?${qstring}`
return encodeURI(`${window.location.origin}/api/qrcode?${qstring}`)
}
const copyBtn = document.getElementById("copyurl")
copyBtn.addEventListener("click", () => copyUrl())
@@ -136,7 +136,6 @@ function copyUrl () {
copyBtn.innerText = "Copy image URL"
copyBtn.classList.remove("success")
}, 750)
} catch (error) {
console.error(error)
copyBtn.innerText = "Failed!"
@@ -145,7 +144,6 @@ function copyUrl () {
copyBtn.innerText = "Copy image URL"
copyBtn.classList.remove("error")
}, 750)
}
}
</script>