Skip to content

Commit

Permalink
sanitize mint URL before adding
Browse files Browse the repository at this point in the history
  • Loading branch information
callebtc committed Aug 9, 2024
1 parent 9f57bd4 commit d652dea
Showing 1 changed file with 22 additions and 2 deletions.
24 changes: 22 additions & 2 deletions src/components/MintSettings.vue
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@
rounded
dense
outlined
@keydown.enter.prevent="showAddMintDialog = true"
@keydown.enter.prevent="sanitizeMintUrlAndShowAddDialog"
v-model="addMintData.url"
placeholder="https://"
ref="mintInput"
Expand All @@ -133,6 +133,7 @@
rounded
dense
outlined
@keydown.enter.prevent="sanitizeMintUrlAndShowAddDialog"
v-model="addMintData.nickname"
label="Nickname (e.g. Testnet)"
ref="mintNicknameInput"
Expand All @@ -147,7 +148,7 @@
color="primary"
:disabled="addMintData.url.length == 0"
:loading="addMintBlocking"
@click="showAddMintDialog = true"
@click="sanitizeMintUrlAndShowAddDialog"
>
<q-icon size="xs" name="add" class="q-pr-xs" />
Add mint
Expand Down Expand Up @@ -609,6 +610,25 @@ export default defineComponent({
this.editMintData = Object.assign({}, mint);
this.showEditMintDialog = true;
},
validateMintUrl: function (url) {
try {
new URL(url);
return true;
} catch (e) {
return false;
}
},
sanitizeMintUrlAndShowAddDialog: function () {
if (!this.validateMintUrl(this.addMintData.url)) {
notifyError("Invalid URL");
return;
}
let urlObj = new URL(this.addMintData.url);
urlObj.hostname = urlObj.hostname.toLowerCase();
this.addMintData.url = urlObj.toString();
this.addMintData.url = this.addMintData.url.replace(/\/$/, "");
this.showAddMintDialog = true;
},
addMintInternal: function (mintToAdd, verbose) {
this.addingMint = true;
try {
Expand Down

0 comments on commit d652dea

Please sign in to comment.