diff --git a/packages/hoppscotch-app/components/http/Request.vue b/packages/hoppscotch-app/components/http/Request.vue index d2d1b1385..f9600f608 100644 --- a/packages/hoppscotch-app/components/http/Request.vue +++ b/packages/hoppscotch-app/components/http/Request.vue @@ -348,7 +348,8 @@ const newSendRequest = async () => { const ensureMethodInEndpoint = () => { if ( !/^http[s]?:\/\//.test(newEndpoint.value) && - !newEndpoint.value.startsWith("<<") + !newEndpoint.value.startsWith("<<") && + !newEndpoint.value.startsWith("{{") ) { const domain = newEndpoint.value.split(/[/:#?]+/)[0] if (domain === "localhost" || /([0-9]+\.)*[0-9]/.test(domain)) { diff --git a/packages/hoppscotch-app/components/http/Variables.vue b/packages/hoppscotch-app/components/http/Variables.vue index d7e8ff06a..daf98d62d 100644 --- a/packages/hoppscotch-app/components/http/Variables.vue +++ b/packages/hoppscotch-app/components/http/Variables.vue @@ -3,7 +3,7 @@
- +
const aggregateVars = useReadonlyStream(restVars$, []) as Ref +const aggregateVars = useReadonlyStream(restVars$, []) as Ref + const envVars = computed(() => props.envs ? props.envs.map((x) => ({ diff --git a/packages/hoppscotch-app/helpers/utils/EffectiveURL.ts b/packages/hoppscotch-app/helpers/utils/EffectiveURL.ts index c90c012b0..d2ede9952 100644 --- a/packages/hoppscotch-app/helpers/utils/EffectiveURL.ts +++ b/packages/hoppscotch-app/helpers/utils/EffectiveURL.ts @@ -14,7 +14,7 @@ import { HoppRESTHeader, HoppRESTParam, } from "@hoppscotch/data" -import { parseTemplateStringV } from "@hoppscotch/data/src/pathVariables" +import { parseTemplateStringV } from "@hoppscotch/data/src/variables" import { arrayFlatMap, arraySort } from "../functional/array" import { toFormData } from "../functional/formData" import { tupleToRecord } from "../functional/record" diff --git a/packages/hoppscotch-data/src/environment.ts b/packages/hoppscotch-data/src/environment.ts index 1a6e58b36..1436208eb 100644 --- a/packages/hoppscotch-data/src/environment.ts +++ b/packages/hoppscotch-data/src/environment.ts @@ -12,11 +12,10 @@ export type Environment = { export type Variables = { key: string value: string - }[] - +}[] const REGEX_ENV_VAR = /<<([^>]*)>>/g // "<>" -const REGEX_PATHVAR = /{{([^>]*)}}/g // "{{myVariable}}" +const REGEX_PATH_VAR = /{{([^>]*)}}/g // "{{myVariable}}" /** * How much times can we expand environment variables diff --git a/packages/hoppscotch-data/src/pathVariables.ts b/packages/hoppscotch-data/src/variables.ts similarity index 70% rename from packages/hoppscotch-data/src/pathVariables.ts rename to packages/hoppscotch-data/src/variables.ts index 44892680d..239a8d2ac 100644 --- a/packages/hoppscotch-data/src/pathVariables.ts +++ b/packages/hoppscotch-data/src/variables.ts @@ -16,7 +16,7 @@ export type Variables = { }[] const REGEX_ENV_VAR = /<<([^>]*)>>/g // "<>" -const REGEX_PATHVAR = /{{([^>]*)}}/g // "{{myVariable}}" +const REGEX_MY_VAR = /{{([^}]*)}}/g // "{{myVariable}}" /** * How much times can we expand environment variables @@ -32,9 +32,9 @@ const ENV_EXPAND_LOOP = "ENV_EXPAND_LOOP" as const export function parseTemplateStringEV( str: string, variables: Environment["variables"], - pathVariables: Variables + myVariables: Variables ) { - if (!variables || !str || !pathVariables) { + if (!variables || !str || !myVariables) { return E.right(str) } @@ -49,10 +49,13 @@ export function parseTemplateStringEV( depth++ } - while (result.match(REGEX_PATHVAR) != null && depth <= ENV_MAX_EXPAND_LIMIT) { + /** + * TODO: Create an error state when there is a suspected loop while recursively expanding these variables + */ + while (result.match(REGEX_MY_VAR) != null && depth <= ENV_MAX_EXPAND_LIMIT) { result = decodeURI(encodeURI(result)).replace( - REGEX_PATHVAR, - (_, p1) => pathVariables.find((x) => x.key === p1)?.value || "" + REGEX_MY_VAR, + (_, p1) => myVariables.find((x) => x.key === p1)?.value || "" ) } @@ -62,15 +65,14 @@ export function parseTemplateStringEV( } /** - * @deprecated Use `parseTemplateStringE` instead + * @deprecated Use `parseTemplateStringEV` instead */ export const parseTemplateStringV = ( str: string, variables: Environment["variables"], - pathVariables: Variables + myVariables: Variables ) => pipe( - parseTemplateStringEV(str, variables, pathVariables), + parseTemplateStringEV(str, variables, myVariables), E.getOrElse(() => str) ) -