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

fix: remove escaping for ConstantAttribute (#293) #295

Merged
merged 10 commits into from
Nov 14, 2023
2 changes: 1 addition & 1 deletion .version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.2.468
0.2.470
2 changes: 1 addition & 1 deletion benchmarks/templ/template.templ
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package testhtml
templ Render(p Person) {
<div>
<h1>{ p.Name }</h1>
<div style="font-family: &#39;sans-serif&#39;" id="test" data-contents={ `something with "quotes" and a <tag>` }>
<div style="font-family: 'sans-serif'" id="test" data-contents={ `something with "quotes" and a <tag>` }>
<div>email:<a href={ templ.URL("mailto: " + p.Email) }>{ p.Email }</a></div>
</div>
</div>
Expand Down
2 changes: 1 addition & 1 deletion generator/test-a-href/template.templ
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package testahref

templ render() {
<a href="javascript:alert(&#39;unaffected&#39;);">Ignored</a>
<a href="javascript:alert('unaffected');">Ignored</a>
<a href={ templ.URL("javascript:alert('should be sanitized')") }>Sanitized</a>
<a href={ templ.SafeURL("javascript:alert('should not be sanitized')") }>Unsanitized</a>
}
6 changes: 3 additions & 3 deletions generator/test-complex-attributes/template.templ
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ package testcomplexattributes

templ ComplexAttributes() {
<div
x-data="{darkMode: localStorage.getItem(&#39;darkMode&#39;) || localStorage.setItem(&#39;darkMode&#39;, &#39;system&#39;)}"
x-init="$watch(&#39;darkMode&#39;, val =&gt; localStorage.setItem(&#39;darkMode&#39;, val))"
:class="{&#39;dark&#39;: darkMode === &#39;dark&#39; || (darkMode === &#39;system&#39; &amp;&amp; window.matchMedia(&#39;(prefers-color-scheme: dark)&#39;).matches)}"
x-data="{darkMode: localStorage.getItem('darkMode') || localStorage.setItem('darkMode', 'system')}"
x-init="$watch('darkMode', val => localStorage.setItem('darkMode', val))"
:class="{'dark': darkMode === 'dark' || (darkMode === 'system' && window.matchMedia('(prefers-color-scheme: dark)').matches)}"
></div>
<div x-data="{ count: 0 }">
<button
Expand Down
2 changes: 1 addition & 1 deletion generator/test-form-action/template.templ
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package testahref

templ render() {
<form action="javascript:alert(&#39;unaffected&#39;);">Ignored</form>
<form action="javascript:alert('unaffected');">Ignored</form>
<form action={ templ.URL("javascript:alert('should be sanitized')") }>Sanitized</form>
<form action={ templ.SafeURL("javascript:alert('should not be sanitized')") }>Unsanitized</form>
}
2 changes: 1 addition & 1 deletion generator/test-html/template.templ
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package testhtml
templ render(p person) {
<div>
<h1>{ p.name }</h1>
<div style="font-family: &#39;sans-serif&#39;" id="test" data-contents={ `something with "quotes" and a <tag>` }>
<div style="font-family: 'sans-serif'" id="test" data-contents={ `something with "quotes" and a <tag>` }>
<div>email:<a href={ templ.URL("mailto: " + p.email) }>{ p.email }</a></div>
</div>
</div>
Expand Down
4 changes: 2 additions & 2 deletions generator/test-script-usage/template.templ
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ templ Button(text string) {
templ ThreeButtons() {
{! Button("A") }
@Button("B")
<button onMouseover="console.log(&#39;mouseover&#39;)" type="button">Button C</button>
<button hx-on::click="alert(&#39;clicked inline&#39;)" type="button">Button D</button>
<button onMouseover="console.log('mouseover')" type="button">Button C</button>
<button hx-on::click="alert('clicked inline')" type="button">Button D</button>
<button hx-on::click={ onClick() } type="button">Button E</button>
@Conditional(true)
}
Expand Down
3 changes: 1 addition & 2 deletions parser/v2/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"errors"
"fmt"
"go/format"
"html"
"io"
"strings"
"unicode"
Expand Down Expand Up @@ -665,7 +664,7 @@ type ConstantAttribute struct {
}

func (ca ConstantAttribute) String() string {
return ca.Name + `="` + html.EscapeString(ca.Value) + `"`
return ca.Name + `="` + ca.Value + `"`
}

func (ca ConstantAttribute) Write(w io.Writer, indent int) error {
Expand Down