🐛 Squashed a minor bug in URL validation

This commit is contained in:
liyasthomas
2019-08-22 21:53:18 +05:30
parent cdea0ff01b
commit dc278cc0e5
2 changed files with 13 additions and 8 deletions

View File

@@ -26,11 +26,17 @@ const app = new Vue({
headers: '', headers: '',
body: '' body: ''
}, },
history: window.localStorage.getItem("history") ? JSON.parse(window.localStorage.getItem("history")) : [] history: window.localStorage.getItem('history') ? JSON.parse(window.localStorage.getItem('history')) : []
}, },
computed: { computed: {
urlNotValid() { urlNotValid() {
return !(/(http(s)?:\/\/.)?(www\.)?[-a-zA-Z0-9@:%._\+~#=]{2,256}\.[a-z]{2,6}\b([-a-zA-Z0-9@:%_\+.~#?&//=]*)/g.test(this.url)) const pattern = new RegExp('^(https?:\\/\\/)?' +
'((([a-z\\d]([a-z\\d-]*[a-z\\d])*)\\.)+[a-z]{2,}|' +
'((\\d{1,3}\\.){3}\\d{1,3}))' +
'(\\:\\d+)?(\\/[-a-z\\d%_.~+]*)*' +
'(\\?[;&a-z\\d%_.~+=-]*)?' +
'(\\#[-a-z\\d_]*)?$', 'i')
return !pattern.test(this.url)
}, },
rawRequestBody() { rawRequestBody() {
const { const {
@@ -71,7 +77,7 @@ const app = new Vue({
methods: { methods: {
deleteHistory(entry) { deleteHistory(entry) {
this.history.splice(this.history.indexOf(entry), 1) this.history.splice(this.history.indexOf(entry), 1)
window.localStorage.setItem("history", JSON.stringify(this.history)) window.localStorage.setItem('history', JSON.stringify(this.history))
}, },
useHistory({ useHistory({
method, method,
@@ -90,18 +96,17 @@ const app = new Vue({
}, },
sendRequest() { sendRequest() {
if (this.urlNotValid) { if (this.urlNotValid) {
alert("Please check the formatting of the URL") alert('Please check the formatting of the URL')
return return
} }
const n = new Date().toLocaleTimeString() const n = new Date().toLocaleTimeString()
// Latest requests should be placed on top
this.history = [{ this.history = [{
time: n, time: n,
method: this.method, method: this.method,
url: this.url, url: this.url,
path: this.path path: this.path
}, ...this.history] }, ...this.history]
window.localStorage.setItem("history", JSON.stringify(this.history)) window.localStorage.setItem('history', JSON.stringify(this.history))
if (this.$refs.response.classList.contains('hidden')) { if (this.$refs.response.classList.contains('hidden')) {
this.$refs.response.classList.toggle('hidden') this.$refs.response.classList.toggle('hidden')
} }

View File

@@ -2,7 +2,7 @@
--bg-color: #121212; --bg-color: #121212;
--fg-color: #FFF; --fg-color: #FFF;
--ac-color: #51FF0D; --ac-color: #51FF0D;
--err-color: #D0021B; --err-color: #393939;
} }
* { * {
@@ -170,7 +170,7 @@ textarea {
} }
.disabled { .disabled {
background-color: #393939; background-color: var(--err-color);
color: #b2b2b2; color: #b2b2b2;
} }