-
Notifications
You must be signed in to change notification settings - Fork 2.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix(misconf): escape all special sequences #7558
Conversation
Signed-off-by: nikpivkin <[email protected]>
func escapeSpecialSequences(input string) string { | ||
var sb strings.Builder | ||
sb.Grow(len(input)) | ||
for i, r := range input { | ||
if r == '$' || r == '%' { | ||
sb.WriteRune(r) | ||
remain := input[i+1:] | ||
|
||
// it's not a special sequence | ||
if remain == "" || remain[0] != '{' { | ||
continue | ||
} | ||
|
||
// sequence is already escaped | ||
if i > 0 && rune(input[i-1]) == r { | ||
continue | ||
} | ||
|
||
sb.WriteRune(r) | ||
} else { | ||
sb.WriteRune(r) | ||
} | ||
} | ||
return sb.String() | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wonder if hashicorp already has this logic somewhere that we could borrow?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
internal only
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ah bummer
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
could you cite the source in that case?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There's not much left of the source https://github.com/hashicorp/hcl/blob/main/hclwrite/generate.go#L367-L373
Description
Related issues
Checklist