-
-
Notifications
You must be signed in to change notification settings - Fork 278
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add support for plain HTML inside elements, not just Go express…
…ions - fixes #22
- Loading branch information
Showing
18 changed files
with
359 additions
and
72 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,8 @@ | ||
{% package testahref %} | ||
|
||
{% templ render() %} | ||
<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> | ||
<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> | ||
{% endtempl %} | ||
|
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package testtext | ||
|
||
import ( | ||
"context" | ||
"strings" | ||
"testing" | ||
|
||
"github.com/google/go-cmp/cmp" | ||
) | ||
|
||
const expected = `<div>Name: Luiz Bonfa</div>` + | ||
`<div>Text ` + "`" + `with backticks` + "`" + `</div>` + | ||
`<div>Text ` + "`" + `with backtick` + `</div>` + | ||
`<div>Text ` + "`" + `with backtick alongside variable: ` + `Luiz Bonfa</div>` | ||
|
||
func TestHTML(t *testing.T) { | ||
w := new(strings.Builder) | ||
err := BasicTemplate("Luiz Bonfa").Render(context.Background(), w) | ||
if err != nil { | ||
t.Errorf("failed to render: %v", err) | ||
} | ||
if diff := cmp.Diff(expected, w.String()); diff != "" { | ||
t.Error(diff) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
{% package testtext %} | ||
|
||
{% templ BasicTemplate(name string) %} | ||
<div>Name: {%= name %}</div> | ||
<div>Text `with backticks`</div> | ||
<div>Text `with backtick</div> | ||
<div>Text `with backtick alongside variable: {%= name %}</div> | ||
{% endtempl %} | ||
|
Oops, something went wrong.