-
-
Notifications
You must be signed in to change notification settings - Fork 276
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: demonstrate how URL schemes are restricted unless templ.Saf…
…eURL is used
- Loading branch information
Showing
3 changed files
with
88 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package testhtml | ||
|
||
import ( | ||
"context" | ||
"strings" | ||
"testing" | ||
|
||
"github.com/google/go-cmp/cmp" | ||
) | ||
|
||
const expected = `<div>` + | ||
`<a href="about:invalid#TemplFailedSanitizationURL"` + | ||
`</div>` | ||
|
||
func TestHTML(t *testing.T) { | ||
w := new(strings.Builder) | ||
err := BasicTemplate(`javascript: alert("xss");`).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,8 @@ | ||
{% package testhtml %} | ||
|
||
{% templ BasicTemplate(url string) %} | ||
<div> | ||
<a href={%= templ.URL(url) %}>{%= "text" %}</a> | ||
</div> | ||
{% endtempl %} | ||
|
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.