fix: highlight environment on string containing dot (#5409)
Co-authored-by: nivedin <nivedinp@gmail.com> Co-authored-by: Nivedin <53208152+nivedin@users.noreply.github.com> Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
This commit is contained in:
parent
35e01e1280
commit
5039a14985
4 changed files with 16 additions and 11 deletions
|
|
@ -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.
|
||||
|
|
|
|||
|
|
@ -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-_]+>>)/g
|
||||
const 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 words
|
||||
let start = pos
|
||||
let 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) ||
|
||||
|
|
|
|||
|
|
@ -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 }
|
||||
|
|
@ -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)
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue