phoenixframework / phoenix_live_view

Rich, real-time user experiences with server-rendered HTML
https://hex.pm/packages/phoenix_live_view
MIT License
6.18k stars 931 forks source link

Compilation error in html.heex #1669

Closed duanzhichao closed 3 years ago

duanzhichao commented 3 years ago

Code

#mix.exs
{:phoenix, "~> 1.6.0"},
{:phoenix_html, "~> 3.0"},
{:phoenix_live_reload, "~> 1.2", only: :dev},
{:phoenix_live_view, "~> 0.16.0"},
{:phoenix_live_dashboard, "~> 0.5"},
{:telemetry_metrics, "~> 0.6.1"},
{:telemetry_poller, "~> 1.0"},
{:gettext, "~> 0.18"},
{:jason, "~> 1.2"},
#html.heex
<div>phoenix</div>
<script>
if (1 < 2) {
  alert('ok')
}
</script>

Error

(Phoenix.LiveView.HTMLTokenizer.ParseError) lib/hitb_web/templates/layout/root.html.heex:241:9: expected tag name
josevalim commented 3 years ago

Thanks for the report @duanzhichao. This has been fixed in master and in the v0.16 branch, so please use one of them until we have a new release.

duanzhichao commented 3 years ago

Thanks for the report @duanzhichao. This has been fixed in master and in the v0.16 branch, so please use one of them until we have a new release.

Thanks

barkerja commented 2 years ago

I just had this error occur with use of (non-compiled) liquid template string examples. For example:

iex(7)> ~H"""
...(7)> <div>
...(7)>   Liquid String Example:
...(7)>   {% if 1 < 2 %}
...(7)>     Example is shown
...(7)>   {% endif %}
...(7)> </div>
...(7)> """
** (Phoenix.LiveView.HTMLTokenizer.ParseError) iex:10:12: expected tag name
    (phoenix_live_view 0.17.11) lib/phoenix_live_view/html_tokenizer.ex:226: Phoenix.LiveView.HTMLTokenizer.handle_tag_open/5
    (phoenix_live_view 0.17.11) lib/phoenix_live_view/html_engine.ex:122: Phoenix.LiveView.HTMLEngine.handle_text/3
    (eex 1.13.3) lib/eex/compiler.ex:49: EEx.Compiler.generate_buffer/4
    (phoenix_live_view 0.17.11) expanding macro: Phoenix.LiveView.Helpers.sigil_H/2
    iex:7: (file)

Is this still a bug or is there a known work-around for such cases? It seems like it's any time you have a naked < in your HTML.

iex(8)> ~H|<div>1 < 2</div>|
** (Phoenix.LiveView.HTMLTokenizer.ParseError) iex:9:9: expected tag name
    (phoenix_live_view 0.17.11) lib/phoenix_live_view/html_tokenizer.ex:226: Phoenix.LiveView.HTMLTokenizer.handle_tag_open/5
    (phoenix_live_view 0.17.11) lib/phoenix_live_view/html_engine.ex:122: Phoenix.LiveView.HTMLEngine.handle_text/3
    (eex 1.13.3) lib/eex/compiler.ex:49: EEx.Compiler.generate_buffer/4
    (phoenix_live_view 0.17.11) expanding macro: Phoenix.LiveView.Helpers.sigil_H/2
    iex:8: (file)
barkerja commented 2 years ago

Would this be resolved by a lookahead in the parser, only raising an error for expected tag name if an opening tag (<) is followed immediately by an allowed character for tag names?