jdrouet / mrml

Implementation of mjml in rust
MIT License
330 stars 19 forks source link

UnexpectedToken with HTML comments in mj-head #373

Closed eisterman closed 5 months ago

eisterman commented 6 months ago

In my project I was using MRML to parse a complex mjml template, but I obtained every time the error

     Finished dev [unoptimized + debuginfo] target(s) in 0.01s
     Running `target/debug/mjml_test`
thread 'main' panicked at src/main.rs:10:38:
parse template: UnexpectedToken(Span { start: 25, end: 45 })
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

After some trial and error I found out that when I have a HTML comment like <!-- things --> anywhere inside the <mj-head> block the parser fails with UnexpectedToken targeted exactly at the comment.

The example template I used to have the previous error:

<mjml>
  <mj-head>
      <!-- TODO things -->
    <mj-preview>
    </mj-preview>
  </mj-head>
  <mj-body>
    <mj-section>
      <mj-column>
        <mj-image width="100px" src="https://www.google.com/images/branding/googlelogo/1x/googlelogo_color_272x92dp.png"></mj-image>
        <mj-divider border-color="#F45E43"></mj-divider>
        <mj-text font-size="20px" color="#F45E43" font-family="helvetica">Hello Test World</mj-text>
      </mj-column>
    </mj-section>
  </mj-body>
</mjml>

The parser crashes even if the comment is inside <mj-preview> but not if it's inside <mj-body>

Edit: I'm using MJML version 2.1.1 but I've found the problem is present on the last version 3.0.1 too

quentindemetz commented 2 months ago

Hi there, I'm getting a similar error with comments inside a mj-attributes block 😉