Skip to content

Heredocs should interpret backslash character literally #262

Closed

Description

@DaveCTurner

Describe the bug

https://developer.hashicorp.com/terraform/language/expressions/strings#escape-sequences-1 says

Backslash sequences are not interpreted as escapes in a heredoc string expression. Instead, the backslash character is interpreted literally.

However, python-hcl2 appears to process backslash sequences in heredocs as if they were in a literal string.

Software:

  • OS: Mac OS Tahoe 26.3 (25D125)
  • Python version: Python 3.13.7
  • python-hcl2 version: main (currently a8e5ac0)

Snippet of HCL2 code causing the unexpected behaviour:

block "example" {
  value = <<-EOT
value with "quoted" word and \"escaped\" quote
and literal \n newline on line two
EOT
}

Expected behavior

{
  "block": [
    {
      "example": {
        "value": "value with \"quoted\" word and \\\"escaped\\\" quote\nand literal \\n newline on line two"
      }
    }
  ]
}

Actual behavior

{
  "block": [
    {
      "example": {
        "value": "value with \"quoted\" word and \"escaped\" quote\nand literal \n newline on line two"
      }
    }
  ]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

bug

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions