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

Allow " (qoute) in hash string param #29

Closed
bckfnn opened this issue Jul 2, 2012 · 2 comments
Closed

Allow " (qoute) in hash string param #29

bckfnn opened this issue Jul 2, 2012 · 2 comments
Assignees
Milestone

Comments

@bckfnn
Copy link

bckfnn commented Jul 2, 2012

handlebars.js allow for escaping a quote with a backslash: (from handlebars.l)

  <mu>'"'("\\"["]|[^"])*'"'        { yytext = yytext.substr(1,yyleng-2).replace(/\\"/g,'"'); return 'STRING'; }

but if I try this template I get a compile error:

  {{#each a="1\"2"}}{{/each}}
@bckfnn
Copy link
Author

bckfnn commented Jul 2, 2012

This hack to Parser.java seem to work, but I'm a parboiled noob so there may be better solutions:

@Label("string")
Rule string(final Var<Object> value) {
    return Sequence(stringLiteral(), value.set(match().replace("\\\"", "\"")));
}

@Label("string")
Rule stringLiteral() {
    return Sequence('"',
            ZeroOrMore(
            FirstOf(
                    String("\\\""),
                    Sequence(TestNot(AnyOf("\"\r\n")), ANY))),
            '"');
}

@jknack
Copy link
Owner

jknack commented Jul 2, 2012

Seems to be a valid solution, can you send a pull request?

I'll write a unit test later.

Thank you.

jknack added a commit that referenced this issue Jul 2, 2012
@jknack jknack closed this as completed Jul 3, 2012
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

2 participants