Open-Source API Development Ecosystem • https://hoppscotch.io • Offline, On-Prem & Cloud • Web, Desktop & CLI • Open-Source Alternative to Postman, Insomnia
TypeScript apiapi-clientapi-restapi-testingdeveloper-toolsgraphqlhttphttp-clientpwarestrest-apispatestingtesting-toolstoolsvuevuejswebsocket
fix: highlight environment on string containing dot (#5409)
Sourav Agrawal5039a149859a
diff --git a/packages/hoppscotch-common/src/helpers/curl/curlparser.ts b/packages/hoppscotch-common/src/helpers/curl/curlparser.tsindex c116bd820..d721c4db0 100644--- a/packages/hoppscotch-common/src/helpers/curl/curlparser.ts+++ b/packages/hoppscotch-common/src/helpers/curl/curlparser.ts@@ -25,15 +25,10 @@ import { getMethod } from "./sub_helpers/method"import { preProcessCurlCommand } from "./sub_helpers/preproc"import { getQueries } from "./sub_helpers/queries"import { concatParams, getURLObject } from "./sub_helpers/url"+import { HOPP_ENVIRONMENT_REGEX } from "../environment-regex"const defaultRESTReq = getDefaultRESTRequest()-/**- * Regex to match environment variables in the format `<<variable_name>>`.- * This is used to identify if the request contains environment variables that need to be handled specially.- */-const HOPP_ENVIRONMENT_REGEX = /(<<[a-zA-Z0-9-_]+>>)/g-/**** @param str The string to test for environment variables.diff --git a/packages/hoppscotch-common/src/helpers/editor/extensions/HoppEnvironment.ts b/packages/hoppscotch-common/src/helpers/editor/extensions/HoppEnvironment.tsindex 10c9ec272..a74423265 100644--- a/packages/hoppscotch-common/src/helpers/editor/extensions/HoppEnvironment.ts+++ b/packages/hoppscotch-common/src/helpers/editor/extensions/HoppEnvironment.ts@@ -37,8 +37,11 @@ import IconLibrary from "~icons/lucide/library?raw"import { isComment } from "./helpers"import { transformInheritedCollectionVariablesToAggregateEnv } from "~/helpers/utils/inheritedCollectionVarTransformer"import { HoppInheritedProperty } from "~/helpers/types/HoppInheritedProperties"+import {+ ENV_VAR_NAME_REGEX,+ HOPP_ENVIRONMENT_REGEX,+} from "~/helpers/environment-regex"-const HOPP_ENVIRONMENT_REGEX = /(<<[a-zA-Z0-9-_]+>>)/gconst HOPP_ENV_HIGHLIGHT ="cursor-help transition rounded px-1 focus:outline-none mx-0.5 env-highlight"const HOPP_REQUEST_VARIABLE_HIGHLIGHT = "request-variable-highlight"@@ -98,9 +101,9 @@ const cursorTooltipField = (aggregateEnvs: AggregateEnvironment[]) =>// Tracking the start and the end of the wordslet start = poslet end = pos- while (start > from && /[a-zA-Z0-9-_]+/.test(text[start - from - 1]))+ while (start > from && ENV_VAR_NAME_REGEX.test(text[start - from - 1]))start--- while (end < to && /[a-zA-Z0-9-_]+/.test(text[end - from])) end+++ while (end < to && ENV_VAR_NAME_REGEX.test(text[end - from])) end++if ((start === pos && side < 0) ||diff --git a/packages/hoppscotch-common/src/helpers/environment-regex.ts b/packages/hoppscotch-common/src/helpers/environment-regex.tsnew file mode 100644index 000000000..b462c2aa4--- /dev/null+++ b/packages/hoppscotch-common/src/helpers/environment-regex.ts@@ -0,0 +1,8 @@+// Regex to match environment variables in the format `<<variable_name>>`/`<<variable.name>>` etc.+// This is used to identify if the request contains environment variables that need to be handled specially.++const ENV_VAR_NAME_PATTERN = "[a-zA-Z0-9_.-]+"+const HOPP_ENVIRONMENT_REGEX = new RegExp(`(<<${ENV_VAR_NAME_PATTERN}>>)`, "g")+const ENV_VAR_NAME_REGEX = new RegExp(ENV_VAR_NAME_PATTERN)++export { HOPP_ENVIRONMENT_REGEX, ENV_VAR_NAME_REGEX }diff --git a/packages/hoppscotch-common/src/services/inspection/inspectors/environment.inspector.ts b/packages/hoppscotch-common/src/services/inspection/inspectors/environment.inspector.tsindex 947b16fd7..323eb2c3a 100644--- a/packages/hoppscotch-common/src/services/inspection/inspectors/environment.inspector.ts+++ b/packages/hoppscotch-common/src/services/inspection/inspectors/environment.inspector.ts@@ -25,8 +25,7 @@ import { SecretEnvironmentService } from "~/services/secret-environment.service"import { RESTTabService } from "~/services/tab/rest"import { CurrentValueService } from "~/services/current-environment-value.service"import { transformInheritedCollectionVariablesToAggregateEnv } from "~/helpers/utils/inheritedCollectionVarTransformer"--const HOPP_ENVIRONMENT_REGEX = /(<<[a-zA-Z0-9-_]+>>)/g+import { HOPP_ENVIRONMENT_REGEX } from "~/helpers/environment-regex"const isENVInString = (str: string) => HOPP_ENVIRONMENT_REGEX.test(str)