nurugger07 / calliope

An elixir haml parser

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Javascript rendering is broken

zwippie opened this issue · comments

Javascript code following a :javascript filter does not get any special treatment, but is tokenized and parsed like regular html code. Therefore calliope will crash or produce incorrect output when a line of (properly indented) javascript code is processed that starts with a (, { or ! etc; characters often found at the start of a line of js code.

To reproduce this bug, create the following test at test/calliope/render_test.exs:56:

  test :render_javascript do
    expected = """
      <script type="text/javascript">
        (function() { console.log("Ok"); }).call(this);
      </script>
      """

    haml = """
      :javascript
        (function() { console.log("Ok"); }).call(this);
      """

    assert_equivalent_html(expected, render(haml))
  end

which results in this error:

  1) test render_javascript (CalliopeRenderTest)
     test/calliope/render_test.exs:56
     ** (CalliopeException) Invalid attribute 'function(' on line number 2`
     code: assert_equivalent_html(expected, render(haml))
     stacktrace:
       (calliope) lib/calliope/parser.ex:184: Calliope.Parser.raise_error/3
       (calliope) lib/calliope/parser.ex:141: Calliope.Parser.merge_attributes/2
       (calliope) lib/calliope/parser.ex:39: Calliope.Parser.parse_line/2
       (calliope) lib/calliope/parser.ex:22: Calliope.Parser.parse_lines/1
       (calliope) lib/calliope/parser.ex:22: Calliope.Parser.parse_lines/1
       (calliope) lib/calliope/parser.ex:18: Calliope.Parser.parse/1
       (calliope) lib/calliope/render.ex:7: Calliope.Render.precompile/1
       test/calliope/render_test.exs:4: CalliopeRenderTest.render/2
       test/calliope/render_test.exs:68: (test)
Erlang/OTP 20 [erts-9.3] [source] [64-bit] [smp:2:2] [ds:2:2:10] [async-threads:10] [hipe] [kernel-poll:false]
Elixir 1.6.5 (compiled with OTP 19)
calliope 0.4.2