You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit 45ccff0
Browse filesBrowse the repository at this point in the historyBrowse files
fix(lib): escape object keys in expressions and hcl maps (#569)
### Related issue
Fixes#350
### Description
Object keys in expressions and HCL maps are now serialized through one
shared quoted-string helper, `quotedStringKey`. Before this change, the
direct-object branches of `resolveExpressionPart` and the HCL map
renderer interpolated keys without escaping.
- Keys escape quotes, backslashes, control characters, `${` (to `$${`)
and `%{` (to `%%{`).
- Backspace and form feed use `\u0008` and `\u000c`. Terraform quoted
strings reject the `\b` and `\f` escapes that `JSON.stringify` emits.
- HCL map keys keep `${...}`, so token references stay interpolations.
- A key built from a token renders as a parenthesised key expression,
for example `(resource.id) = "v"`. HCL has no interpolation syntax for
object keys.
- A key that mixes literal text and a token escapes the literal fragment
with the same rules as a plain key. It then emits the token as `${...}`,
for example `("pre-${resource.id}") = "v"`.
- A property whose value resolves to `undefined` (for example
`Lazy.anyValue`) is omitted. This matches the existing behavior for a
literal `undefined` value.
**Behavior change:** a literal `${...}` key in an `Fn.*` object argument
is now escaped and kept as text. It is no longer evaluated as an
interpolation. For example, `Fn.keys({ "${resource.id}": "v" })` used to
resolve the reference. It now keeps the text `${resource.id}` as the
key. Configurations that relied on the old evaluation will show a plan
diff. To use a reference as a key, pass the token itself, for example `{
[resource.id]: "v" }`.
### Checklist
- [x] I have updated the PR title to match [CDKTN's style
guide](https://github.com/open-constructs/cdk-terrain/blob/main/CONTRIBUTING.md#pull-requests-1)
- [x] I have run the linter on my code locally
- [x] I have performed a self-review of my code
- [x] I have commented my code, particularly in hard-to-understand areas
- [ ] I have made corresponding changes to the
[documentation](https://github.com/open-constructs/cdk-terrain-docs/tree/main/content)
if applicable
- [x] My changes generate no new warnings
- [x] I have added tests that prove my fix is effective or that my
feature works if applicable
- [x] New and existing unit tests pass locally with my changes
0 commit comments