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

Unmatched BRACE_OPEN error when using ) in blocks #26

Closed
goloroden opened this issue Dec 31, 2013 · 18 comments
Closed

Unmatched BRACE_OPEN error when using ) in blocks #26

goloroden opened this issue Dec 31, 2013 · 18 comments

Comments

@goloroden
Copy link

Supposed you have this file as layout.vash

<!doctype html>
<html>
  <head>
    <title>dotnetpro-Store</title>
  </head>

  <body>
    @html.block('content')
  </body>
</html>

and this file as index.vash:

@html.extend('layout', function (model) {
  @html.block('content', function (model) {
    <p>Hello world :-)!</p>
  })
})

Then rendering of index.vash crashes with the following error message:

UnmatchedCharacterError: Unmatched BRACE_OPEN at line 1, character 40. Value: {

The problem is the ) character in the text that shall be printed out. It does not matter whether it's a smiley or something else - as soon as there is a closing brace, the template can not be rendered.

How to solve this?

PS: Of course, a similar problem happens when using the } character.

@kirbysayshi
Copy link
Owner

Yep, definitely a bug. Thanks for reporting it so clearly! I'll try to get to it tonight or tomorrow.

In the meantime, you can prefix ) with an @ while in content mode to escape it. This is slightly intentional behavior, but isn't really documented because it breaks on anything that could trigger a switch to an expression or block, such as a valid JS identifier, (, {, js keyword (switch, if, etc), or function.

So your example could be:

@html.extend('layout', function (model) {
  @html.block('content', function (model) {
    <p>Hello world :-@)!</p>
  })
})

@kirbysayshi
Copy link
Owner

I was able to make simpler test cases:

@(function() { <p>)</p> })

and

@{ function what() { <p>}</p> } }

In both cases, that content should not be counted as ending the expression or block. Using @ as an escape as mentioned above is your best bet for now, although that particular escape is meant to cover the case of:

@('@)')

Since vash does not have a concept of "within a string" when in code mode.

@goloroden
Copy link
Author

Thanks for replying that fast :-)!

Great to have this workaround at hand! Thanks a lot!

@sowee15
Copy link

sowee15 commented Aug 23, 2014

Hi, will this also fix an error I am having where there is an unclosed parenthesis in a javascript comment in a view? For instance, this view:

    @html.extend('layout', function(model) {
        @html.block('content', function(model) {
            <script>
            // this is a comment (
            </script>
        })
    })

this will make the engine crash. If I close the parenthesis on the comment line, it works fine.
Thanks!

@kirbysayshi
Copy link
Owner

Yes, if you prefix it with a @ it shouldn't crash anymore.

@sowee15
Copy link

sowee15 commented Aug 26, 2014

My first thought was that comments were ignored in terms of matching document structure, like parenthesis and braces. Next time I'll surely spot that kind of error faster though. Shouldn't they (comments) be ignored when checking document structure integrity?

@kirbysayshi
Copy link
Owner

Absolutely, and the next version of vash will! But the current version doesn't treat comments any differently, and unfortunately I made a bad decision on how to handle characters like ( that typically have a matching counterpart.

@sowee15
Copy link

sowee15 commented Aug 26, 2014

Oh then I misunderstood your first answer, I thought the final solution was to prefix those chars (in comments too). Thanks for the follow up and for the module!

@v3rt1go
Copy link

v3rt1go commented Oct 30, 2014

Hi,

It seems there still is an issue with text parentheses in code blocks.
For the closing ) the workaround with escaping it with @ works, but for opening ( does not.

For example, this works:

@if (model.flash_error) {
    <p class="text-error">@model.flash_error happy face :-@)</p>
  }

But switching ) with (:

@if (model.flash_error) {
    <p class="text-error">@model.flash_error sad face :-@(</p>
  }

returns:
UnmatchedCharacterError: Unmatched PAREN_OPEN at line 1, character 12. Value: (
+PROGRAM
| +EXPRESSION
| | [IDENTIFIER (1,1): html]
| | [PERIOD (1,5): .]
| | [IDENTIFIER (1,6): extend]
| -EXPRESSION
-PROGRAM
at Object.VParser.advanceUntilMatched (C:\Users\Alex\Proiecte\TheBoard\node_modules\vash\build\vash.js:629:44)
at Object.VParser.subParse (C:\Users\Alex\Proiecte\TheBoard\node_modules\vash\build\vash.js:643:20)
at Object.VParser.handleEXP (C:\Users\Alex\Proiecte\TheBoard\node_modules\vash\build\vash.js:992:10)
at Object.VParser.parse (C:\Users\Alex\Proiecte\TheBoard\node_modules\vash\build\vash.js:543:10)
at Object.compile (C:\Users\Alex\Proiecte\TheBoard\node_modules\vash\build\vash.js:1319:4)
at Object.vash.loadFile (C:\Users\Alex\Proiecte\TheBoard\node_modules\vash\build\vash.js:2068:12)
at View.vash.renderFile as engine
at View.render (C:\Users\Alex\Proiecte\TheBoard\node_modules\express\lib\view.js:93:8)
at EventEmitter.app.render (C:\Users\Alex\Proiecte\TheBoard\node_modules\express\lib\application.js:530:10)
at ServerResponse.res.render (C:\Users\Alex\Proiecte\TheBoard\node_modules\express\lib\response.js:904:7)

@kirbysayshi
Copy link
Owner

Hey @v3rt1go! Have you tried removing the @? I tried your code snippet, and it parsed and rendered fine. Using an explicit @( implies an explicit expression: @(something).

@v3rt1go
Copy link

v3rt1go commented Oct 31, 2014

Hi! Thanks for coming back so fast.
I did try to remove the leading @ but I get the same:

@if (model.flash_error) {
    <p class="text-error">@model.flash_error sad face :-(</p>
  }

Output:
UnmatchedCharacterError: Unmatched PAREN_OPEN at line 1, character 12. Value: (
+PROGRAM
| +EXPRESSION
| | [IDENTIFIER (1,1): html]
| | [PERIOD (1,5): .]
| | [IDENTIFIER (1,6): extend]
| -EXPRESSION
-PROGRAM
at Object.VParser.advanceUntilMatched (C:\Users\Alex\Proiecte\TheBoard\node_modules\vash\build\vash.js:629:44)
at Object.VParser.subParse (C:\Users\Alex\Proiecte\TheBoard\node_modules\vash\build\vash.js:643:20)
at Object.VParser.handleEXP (C:\Users\Alex\Proiecte\TheBoard\node_modules\vash\build\vash.js:992:10)
at Object.VParser.parse (C:\Users\Alex\Proiecte\TheBoard\node_modules\vash\build\vash.js:543:10)
at Object.compile (C:\Users\Alex\Proiecte\TheBoard\node_modules\vash\build\vash.js:1319:4)
at Object.vash.loadFile (C:\Users\Alex\Proiecte\TheBoard\node_modules\vash\build\vash.js:2068:12)
at View.vash.renderFile as engine
at View.render (C:\Users\Alex\Proiecte\TheBoard\node_modules\express\lib\view.js:93:8)
at EventEmitter.app.render (C:\Users\Alex\Proiecte\TheBoard\node_modules\express\lib\application.js:530:10)
at ServerResponse.res.render (C:\Users\Alex\Proiecte\TheBoard\node_modules\express\lib\response.js:904:7)

@kirbysayshi
Copy link
Owner

@v3rt1go I'm definitely not getting that in the playground: http://codepen.io/anon/pen/nlxIJ

What version of vash are you using? Is there more in the template than what you're sharing here?

@v3rt1go
Copy link

v3rt1go commented Nov 2, 2014

Hey @kirbysayshi I'm using vash 0.7.12-1 (installed from npm). I've played with what you've set up on codepen and indeed I cannot reproduce, however it's still reproducible on my end.
You can find the whole code here: https://github.com/v3rt1go/theboard - it's on /vews/index.vash#27

I'm using VS2013 with Node Js tools for VS on the project, though it's a bit far fetched I'm trying to port the whole project in WebStorm or sublime to see if it's a freaky character encoding issue ... though it's far fetched.

@kirbysayshi
Copy link
Owner

@v3rt1go it appears that once you add in the surrounding block the error manifests. The issue is also present in examples such as:

@("(")

and

@(function(model) {
  <p>(</p>
}())

Thanks for sending the surrounding code, that helped. So yes, this is the same issue, and I don't have a great workaround at this time. Although one option is to use the reverse frowny face: @):

@kirbysayshi
Copy link
Owner

@v3rt1go example: http://codepen.io/anon/pen/tlfEa

I'm sorry, I know this is inadequate, but I don't want you to have to wait for a fix.

@meandmycode
Copy link

This is one of few bugs we had found when using vash (the other a similar issue with xml style self terminating elements, such as <br /> instead of <br> but only in certain situations, like this).

When we looked into the code base we saw that parsing was doing a lot of balancing of braces/parenthesis and seemed like it could be quite a task to fix (although I'm sure you'll know better regarding this).

One work around for this which is relatively clean is to balance the parenthesis out using comments, so your code would become:

@if (model.flash_error) {
    <p class="text-error">@model.flash_error sad face :-(</p>@*)*@
}

Thanks.

@kirbysayshi
Copy link
Owner

@meandmycode spectacular! And you're absolutely right: vash takes shortcuts that a parser should not really take by balancing tokens without context (like "is in string" or "is within markup tags"). I believe that it's definitely a non-trivial fix, although perhaps possible. I'd started to rewrite vash to be able to handle these cases on the stated branch, https://github.com/kirbysayshi/vash/tree/ksh/stated/experiments/stated, but got stalled due to other commitments.

kirbysayshi added a commit that referenced this issue Mar 2, 2015
@kirbysayshi
Copy link
Owner

This is fixed as of >= 0.8.0!

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

No branches or pull requests

5 participants