fix: preserve encoded characters in cURL URLs (#4792)

Co-authored-by: nivedin <nivedinp@gmail.com>
Co-authored-by: jamesgeorge007 <25279263+jamesgeorge007@users.noreply.github.com>
This commit is contained in:
Alexandre Rodrigues Batista 2025-07-24 04:44:36 -03:00 committed by GitHub
parent 1f158a19ff
commit 876d0fd322
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -28,6 +28,19 @@ import { concatParams, getURLObject } from "./sub_helpers/url"
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.
* @returns A boolean indicating whether the string contains environment variables.
*/
const containsEnvVariables = (str: string) => HOPP_ENVIRONMENT_REGEX.test(str)
export const parseCurlCommand = (curlCommand: string) => {
// const isDataBinary = curlCommand.includes(" --data-binary")
// const compressed = !!parsedArguments.compressed
@ -150,7 +163,16 @@ export const parseCurlCommand = (curlCommand: string) => {
hasBodyBeenParsed = true
}
const urlString = decodeURIComponent(concatParams(urlObject, danglingParams))
const concatedURL = concatParams(urlObject, danglingParams)
const decodedURL = decodeURIComponent(concatedURL)
// Decode the URL only if its safe to do so without corrupting environment variables.
// This is to ensure that environment variables are not decoded and remain in the format `<<variable_name>>`.
// This is useful for code generation where environment variables are used to store sensitive information
// such as API keys, secrets, etc.
// If the URL does not contain environment variables, decode it normally.
const urlString = containsEnvVariables(decodedURL) ? decodedURL : concatedURL
let multipartUploads: Record<string, string> = pipe(
O.of(parsedArguments),