Skip to content

strip_string_quotes=True turns a literal inside %{ ... } into a bare reference #341

Description

@livingstaccato

Summary

TemplateStringRule.serialize strips the " delimiters whenever
strip_string_quotes is set. That rule only ever appears inside a template
directive, where the text is expression source -- so the delimiters it removes
are a string literal's, not the template's.

Reproduction

hcl2.loads('a = "%{ if x == \\"y\\" }t%{ endif }"\n',
           serialization_options=SerializationOptions(strip_string_quotes=True))["a"]
# '%{ if x == y }t%{ endif }'

The literal "y" has become a reference to y: a different expression, not a
different spelling of the same one. TemplateStringRule.serialize is
hcl2/rules/strings.py:269 at v8.1.3. The source form is correct; only the
value form is affected.

Same root cause as #E above -- a rule inside expression source treating it as
literal text -- but a different rule, so it is filed separately.


This issue, and the investigation behind it, were produced by an AI assistant (Claude) working on behalf of the author. Please review with that provenance in mind.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions