mirror of
https://github.com/gohugoio/hugoDocs.git
synced 2025-09-19 07:54:46 -04:00
Document safe.JSStr function
This commit is contained in:
parent
e77993be08
commit
7551ba28f7
@ -12,6 +12,7 @@ relatedFuncs:
|
||||
- safe.HTML
|
||||
- safe.HTMLAttr
|
||||
- safe.JS
|
||||
- safe.JSStr
|
||||
- safe.URL
|
||||
signature:
|
||||
- safe.CSS INPUT
|
||||
|
@ -12,6 +12,7 @@ relatedFuncs:
|
||||
- safe.HTML
|
||||
- safe.HTMLAttr
|
||||
- safe.JS
|
||||
- safe.JSStr
|
||||
- safe.URL
|
||||
signature:
|
||||
- safe.HTML INPUT
|
||||
|
@ -12,6 +12,7 @@ relatedFuncs:
|
||||
- safe.HTML
|
||||
- safe.HTMLAttr
|
||||
- safe.JS
|
||||
- safe.JSStr
|
||||
- safe.URL
|
||||
signature:
|
||||
- safe.HTMLAttr INPUT
|
||||
|
@ -12,6 +12,7 @@ relatedFuncs:
|
||||
- safe.HTML
|
||||
- safe.HTMLAttr
|
||||
- safe.JS
|
||||
- safe.JSStr
|
||||
- safe.URL
|
||||
signature:
|
||||
- safe.JS INPUT
|
||||
|
59
content/en/functions/safeJSStr.md
Normal file
59
content/en/functions/safeJSStr.md
Normal file
@ -0,0 +1,59 @@
|
||||
---
|
||||
title: safeJSStr
|
||||
description: Declares the provided string as a known safe JavaScript string.
|
||||
categories: [functions]
|
||||
menu:
|
||||
docs:
|
||||
parent: functions
|
||||
keywords: []
|
||||
namespace: safe
|
||||
relatedFuncs:
|
||||
- safe.CSS
|
||||
- safe.HTML
|
||||
- safe.HTMLAttr
|
||||
- safe.JS
|
||||
- safe.JSStr
|
||||
- safe.URL
|
||||
signature:
|
||||
- safe.JSStr INPUT
|
||||
- safeJSStr INPUT
|
||||
---
|
||||
|
||||
Encapsulates a sequence of characters meant to be embedded between quotes in a JavaScript expression. Use of this type presents a security risk: the encapsulated content should come from a trusted source, as it will be included verbatim in the template output.
|
||||
|
||||
Without declaring a variable to be a safe JavaScript string:
|
||||
|
||||
```go-html-template
|
||||
{{ $title := "Lilo & Stitch" }}
|
||||
<script>
|
||||
const a = "Title: " + {{ $title }};
|
||||
</script>
|
||||
```
|
||||
|
||||
Rendered:
|
||||
|
||||
|
||||
```html
|
||||
<script>
|
||||
const a = "Title: " + "Lilo \u0026 Stitch";
|
||||
</script>
|
||||
```
|
||||
|
||||
To avoid escaping by Go's [html/template] package:
|
||||
|
||||
```go-html-template
|
||||
{{ $title := "Lilo & Stitch" }}
|
||||
<script>
|
||||
const a = "Title: " + {{ $title | safeJSStr }};
|
||||
</script>
|
||||
```
|
||||
|
||||
Rendered:
|
||||
|
||||
```html
|
||||
<script>
|
||||
const a = "Title: " + "Lilo & Stitch";
|
||||
</script>
|
||||
```
|
||||
|
||||
[html/template]: https://pkg.go.dev/html/template
|
@ -13,6 +13,7 @@ relatedFuncs:
|
||||
- safe.HTML
|
||||
- safe.HTMLAttr
|
||||
- safe.JS
|
||||
- safe.JSStr
|
||||
- safe.URL
|
||||
signature:
|
||||
- safe.URL INPUT
|
||||
|
Loading…
x
Reference in New Issue
Block a user