From 8b961fb8cdd88e61d1df1346ddfd4e3d16f83b7f Mon Sep 17 00:00:00 2001 From: "Samir L. Boulema" Date: Thu, 7 May 2020 20:54:38 +0200 Subject: [PATCH 1/2] Environment variables in collections #642 --- functions/utils/uri.js | 13 +++++++++++++ pages/index.vue | 17 +++++++---------- 2 files changed, 20 insertions(+), 10 deletions(-) create mode 100644 functions/utils/uri.js diff --git a/functions/utils/uri.js b/functions/utils/uri.js new file mode 100644 index 000000000..3fd4091de --- /dev/null +++ b/functions/utils/uri.js @@ -0,0 +1,13 @@ +export function parseUrlAndPath(value) { + let result = {} + try { + let url = new URL(value) + result.url = url.origin + result.path = url.pathname + } catch (error) { + let uriRegex = value.match(/^((http[s]?:\/\/)?(<<[^\/]+>>)?[^\/]*|)(\/?.*)$/) + result.url = uriRegex[1] + result.path = uriRegex[4] + } + return result; +} \ No newline at end of file diff --git a/pages/index.vue b/pages/index.vue index 3bbc271b2..91133edd5 100644 --- a/pages/index.vue +++ b/pages/index.vue @@ -1330,6 +1330,7 @@ import { sendNetworkRequest } from "../functions/network" import { fb } from "../functions/fb" import { getEditorLangForMimeType } from "~/functions/editorutils" import { hasPathParams, addPathParamsToVariables, getQueryParams } from "../functions/requestParams.js" +import { parseUrlAndPath } from "../functions/utils/uri.js" const statusCategories = [ { name: "informational", @@ -1603,16 +1604,9 @@ export default { environmentVariables = addPathParamsToVariables(this.params, environmentVariables) url = parseTemplateString(value, environmentVariables) } - try { - url = new URL(url) - this.url = url.origin - this.path = url.pathname - } catch (error) { - console.log(error) - let uriRegex = value.match(/^((http[s]?:\/\/)?(<<[^\/]+>>)?[^\/]*|)(\/?.*)$/) - this.url = uriRegex[1] - this.path = uriRegex[4] - } + let result = parseUrlAndPath(url) + this.url = result.url + this.path = result.path }, }, url: { @@ -2633,6 +2627,9 @@ export default { if (this.selectedRequest.url) { this.editRequest = Object.assign({}, this.selectedRequest, this.editRequest) } + let result = parseUrlAndPath(this.uri) + this.url = result.url + this.path = result.path this.showRequestModal = true }, hideRequestModal() { From c655d551979e2e068b5234933a20138c5ea64215 Mon Sep 17 00:00:00 2001 From: "Samir L. Boulema" Date: Fri, 8 May 2020 23:04:02 +0200 Subject: [PATCH 2/2] Always save non replaced uri, but display replaced url in the UI --- pages/index.vue | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/pages/index.vue b/pages/index.vue index 91133edd5..8ad639e55 100644 --- a/pages/index.vue +++ b/pages/index.vue @@ -2182,6 +2182,7 @@ export default { let environmentVariables = getEnvironmentVariablesFromScript(this.preRequestScript) environmentVariables = addPathParamsToVariables(this.params, environmentVariables) entry.path = parseTemplateString(entry.path, environmentVariables) + entry.url = parseTemplateString(entry.url, environmentVariables) } this.$refs.historyComponent.addEntry(entry) @@ -2214,6 +2215,7 @@ export default { let environmentVariables = getEnvironmentVariablesFromScript(this.preRequestScript) environmentVariables = addPathParamsToVariables(this.params, environmentVariables) entry.path = parseTemplateString(entry.path, environmentVariables) + entry.url = parseTemplateString(entry.url, environmentVariables) } this.$refs.historyComponent.addEntry(entry) @@ -2605,9 +2607,10 @@ export default { }) return } + let urlAndPath = parseUrlAndPath(this.uri) this.editRequest = { - url: this.url, - path: this.path, + url: urlAndPath.url, + path: urlAndPath.path, method: this.method, auth: this.auth, httpUser: this.httpUser, @@ -2627,9 +2630,6 @@ export default { if (this.selectedRequest.url) { this.editRequest = Object.assign({}, this.selectedRequest, this.editRequest) } - let result = parseUrlAndPath(this.uri) - this.url = result.url - this.path = result.path this.showRequestModal = true }, hideRequestModal() {