cloudflare / Stout

A reliable static website deploy tool
MIT License
751 stars 29 forks source link

Parsing HTML files containing Django template syntax causes panic #33

Open averagehuman opened 7 years ago

averagehuman commented 7 years ago

One of my pages has some example Django template code displayed within a 'pre' block:

<link rel="stylesheet" href="{% static 'app.css' %}" />

The actual html within the page is:

<span class="p">&lt;</span><span class="nt">link</span> <span class="na">rel</span><span class="o">=</span><span class="s">&quot;stylesheet&quot;</span> <span class="na">href</span><span class="o">=</span><span class="s">&quot;{% static &#39;app.css&#39; %}&quot;</span> <span class="p">/&gt;</span>

The error I get:

panic: parse {% static 'app.css' %}: invalid URL escape "% s"

goroutine 1 [running]:
panic(0x8922e0, 0xc820c07140)
    /usr/local/go/src/runtime/panic.go:481 +0x3e6
main.must(0x8bc480, 0x0, 0x2ab0c51ab080, 0xc820c07140, 0x0, 0x0)
    /Users/zack/s/stout/src/utils.go:86 +0x57
main.isLocal(0xc82125de40, 0x16, 0x8f9840)
    /Users/zack/s/stout/src/deploy.go:239 +0x71
main.parseHTML.func1(0xc821229b90)
    /Users/zack/s/stout/src/deploy.go:345 +0x63e
main.parseHTML.func1(0xc821229960)
    /Users/zack/s/stout/src/deploy.go:319 +0x6f
main.parseHTML.func1(0xc821229880)
    /Users/zack/s/stout/src/deploy.go:319 +0x6f
main.parseHTML.func1(0xc821229810)
    /Users/zack/s/stout/src/deploy.go:319 +0x6f
main.parseHTML(0x8f47d8, 0x1, 0x8f49a0, 0x2, 0x8f49a0, 0x2, 0x0, 0x0, 0x0, 0x0, ...)
    /Users/zack/s/stout/src/deploy.go:357 +0x275
main.Deploy(0x8f47d8, 0x1, 0x8f49a0, 0x2, 0x8f49a0, 0x2, 0x0, 0x0, 0x0, 0x0, ...)
    /Users/zack/s/stout/src/deploy.go:521 +0x8e3
main.deployCmd()
    /Users/zack/s/stout/src/deploy.go:638 +0x137
main.main()
    /Users/zack/s/stout/src/cli.go:39 +0x3e3
renandincer commented 7 years ago

Thanks for reporting this! As an interim solution, can you try using &#37; instead of the percent sign characters? That might solve this issue for the time being.

averagehuman commented 7 years ago

That doesn't work unfortunately. The code snippets are being formatted via pygments, and you can hack things in python with:

from pygments.formatters.html import _escape_html_table                                                                 
 _escape_html_table[ord('%')] = u'&#37;' 

This does escape the percent sign but you end up with an identical error.

Not to worry. The 'stout create' step worked perfectly and I can fall back to 's3cmd sync' for the rest for now. Thanks.