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

Line breaks in literal strings fail to parse #541

Open
mikeclayton opened this issue Apr 19, 2024 · 1 comment
Open

Line breaks in literal strings fail to parse #541

mikeclayton opened this issue Apr 19, 2024 · 1 comment

Comments

@mikeclayton
Copy link

mikeclayton commented Apr 19, 2024

Dotliquid version

2.2.692

Expected behavior

The following template should parse:

mytemplate.liquid

{% capture ATLANTIS_GH_TOKEN %}
--- begin ---
aaa
--- end ---
{% endcapture %}

{{ ATLANTIS_GH_TOKEN | replace: "
", "x" }}

Actual behavior

MethodInvocationException: Exception calling "Parse" with "1" argument(s): "Variable '{{ ATLANTIS_GH_TOKEN | replace: "
", "x" }}' was not properly terminated with regexp: (?-mix:\}\})"

Steps to reproduce the Problem (you can add files)

The following PowerShell sample fails to parse due to the literal line breaks:

[DotLiquid.Template]::Parse(@"
{% capture ATLANTIS_GH_TOKEN %}
--- begin ---
aaa
--- end ---
{% endcapture %}
{{ ATLANTIS_GH_TOKEN | replace: "
", "x" }}
"@)

MethodInvocationException: Exception calling "Parse" with "1" argument(s): "Variable '{{ ATLANTIS_GH_TOKEN | replace: "
", "x" }}' was not properly terminated with regexp: (?-mix:\}\})"

whereas this one works fine without the literal line break:

[DotLiquid.Template]::Parse(@"
{% capture ATLANTIS_GH_TOKEN %}
--- begin ---
aaa
--- end ---
{% endcapture %}
{{ ATLANTIS_GH_TOKEN | replace: "", "x" }}
"@)

Additional Info

It seems that Liquid doesn't have any escape sequences for strings (e.g. "\n" for new line) so they have to be represented verbatim in strings - for line breaks this means actually putting a line break in the source code per above. Other parsers appear to support this - see:

And this stackoverflow answer suggests the same thing:

@mikeclayton
Copy link
Author

The stack trace from the exception is:

PS> $error[0].Exception

ErrorRecord                 : Exception calling "Parse" with "1" argument(s): "Variable '{{ ATLANTIS_GH_TOKEN | replace: "
                              ", "x" }}' was not properly terminated with regexp: (?-mix:\}\})"
WasThrownFromThrowStatement : False
TargetSite                  : Void ConvertToMethodInvocationException(System.Exception, System.Type, System.String, Int32,
                              System.Reflection.MemberInfo)
Message                     : Exception calling "Parse" with "1" argument(s): "Variable '{{ ATLANTIS_GH_TOKEN | replace: "
                              ", "x" }}' was not properly terminated with regexp: (?-mix:\}\})"
Data                        : {[System.Management.Automation.Interpreter.InterpretedFrameInfo,
                              System.Management.Automation.Interpreter.InterpretedFrameInfo[]]}
InnerException              : DotLiquid.Exceptions.SyntaxException: Variable '{{ ATLANTIS_GH_TOKEN | replace: "
                              ", "x" }}' was not properly terminated with regexp: (?-mix:\}\})
                                 at DotLiquid.Block.CreateVariable(String token)
                                 at DotLiquid.Block.Parse(List`1 tokens)
                                 at DotLiquid.Template.ParseInternal(String source, SyntaxCompatibility syntaxCompatibilityLevel)
                                 at CallSite.Target(Closure, CallSite, Type, String)
HelpLink                    :
Source                      : System.Management.Automation
HResult                     : -2146233087
StackTrace                  :    at System.Management.Automation.ExceptionHandlingOps.ConvertToMethodInvocationException(Exception
                              exception, Type typeToThrow, String methodName, Int32 numArgs, MemberInfo memberInfo)
                                 at CallSite.Target(Closure, CallSite, Type, String)
                                 at System.Dynamic.UpdateDelegates.UpdateAndExecute2[T0,T1,TRet](CallSite site, T0 arg0, T1 arg1)
                                 at System.Management.Automation.Interpreter.DynamicInstruction`3.Run(InterpretedFrame frame)
                                 at System.Management.Automation.Interpreter.EnterTryCatchFinallyInstruction.Run(InterpretedFrame frame)

PS> $error[0].Exception.InnerException

TargetSite     : DotLiquid.Variable CreateVariable(System.String)
Message        : Variable '{{ ATLANTIS_GH_TOKEN | replace: "
                 ", "x" }}' was not properly terminated with regexp: (?-mix:\}\})
Data           : {}
InnerException :
HelpLink       :
Source         : DotLiquid
HResult        : -2146232832
StackTrace     :    at DotLiquid.Block.CreateVariable(String token)
                    at DotLiquid.Block.Parse(List`1 tokens)
                    at DotLiquid.Template.ParseInternal(String source, SyntaxCompatibility syntaxCompatibilityLevel)
                    at CallSite.Target(Closure, CallSite, Type, String)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant