Skip to content
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

HCL Parser doesn't support escaping double quote sign in String literals #4612

Closed
mccartney opened this issue Oct 26, 2024 · 1 comment · Fixed by #4665
Closed

HCL Parser doesn't support escaping double quote sign in String literals #4612

mccartney opened this issue Oct 26, 2024 · 1 comment · Fixed by #4665
Labels
bug Something isn't working parser-hcl test provided Already replicated with a unit test, using JUnit pioneer's ExpectedToFail

Comments

@mccartney
Copy link
Contributor

What is the smallest, simplest way to reproduce the problem?

    @Test
    void quoteEscaping() {
        rewriteRun(
          hcl(
            """
              locals {
                quotedText = "this is a double quote: \". Look at me"
              }
              """
          )
        );
    }

What is the full stack trace of any errors you encountered?

[...]
Caused by: org.openrewrite.hcl.HclParsingException: Syntax error in file.tf at line 2:54 token recognition error at: '\n'.
	at org.openrewrite.hcl.HclParser$ForwardingErrorListener.syntaxError(HclParser.java:105)
	... 132 more
Caused by: LexerNoViableAltException('\n')
	at org.antlr.v4.runtime.atn.LexerATNSimulator.failOrAccept(LexerATNSimulator.java:309)
	at org.antlr.v4.runtime.atn.LexerATNSimulator.execATN(LexerATNSimulator.java:230)
	at org.antlr.v4.runtime.atn.LexerATNSimulator.match(LexerATNSimulator.java:114)
	at org.antlr.v4.runtime.Lexer.nextToken(Lexer.java:141)
	... 129 more

Context

AFAICT this is a valid Terraform/HCL file.
https://developer.hashicorp.com/terraform/language/expressions/strings#escape-sequences says this is the proper way of escaping the quote sign.

@mccartney mccartney added the bug Something isn't working label Oct 26, 2024
@timtebeek timtebeek moved this to Backlog in OpenRewrite Oct 26, 2024
@timtebeek timtebeek added the test provided Already replicated with a unit test, using JUnit pioneer's ExpectedToFail label Oct 26, 2024
@mccartney mccartney changed the title HCL Parser doesn't support quoting double quote sign in String literals HCL Parser doesn't support escaping double quote sign in String literals Oct 30, 2024
@mccartney
Copy link
Contributor Author

mccartney commented Nov 12, 2024

Actually I think the description above is wrong. This line:

                quotedText = "this is a double quote: \". Look at me"

"renders" to:

                quotedText = "this is a double quote: ". Look at me"

in HCL.

The backslash is basically swallowed by Java as hinted by Intelli:
image

And if so, the HCL file provided in the test is not a valid Terraform/HCL file. And Rewrite is right when failing.

Sorry for the noise.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working parser-hcl test provided Already replicated with a unit test, using JUnit pioneer's ExpectedToFail
Projects
Archived in project
Development

Successfully merging a pull request may close this issue.

2 participants