Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sanitize mint URL before adding #197

Merged
merged 1 commit into from
Aug 9, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading