Bugfix/Prevent transforming double curly brackets (#4252)

prevent transforming double curly brackets
This commit is contained in:
Henry Heng 2025-04-04 16:19:04 +08:00 committed by GitHub
parent 8e63b999b8
commit b988cae58c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 6 additions and 4 deletions

View File

@ -284,14 +284,16 @@ export const getInputVariables = (paramValue: string): string[] => {
}
/**
* Transform curly braces into double curly braces if the content includes a colon.
* Transform single curly braces into double curly braces if the content includes a colon.
* @param input - The original string that may contain { ... } segments.
* @returns The transformed string, where { ... } containing a colon has been replaced with {{ ... }}.
*/
export const transformBracesWithColon = (input: string): string => {
// This regex will match anything of the form `{ ... }` (no nested braces).
// `[^{}]*` means: match any characters that are not `{` or `}` zero or more times.
const regex = /\{([^{}]*?)\}/g
// This regex uses negative lookbehind (?<!{) and negative lookahead (?!})
// to ensure we only match single curly braces, not double ones.
// It will match a single { that's not preceded by another {,
// followed by any content without braces, then a single } that's not followed by another }.
const regex = /(?<!\{)\{([^{}]*?)\}(?!\})/g
return input.replace(regex, (match, groupContent) => {
// groupContent is the text inside the braces `{ ... }`.