escape

package
v1.0.6 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 1, 2023 License: MIT Imports: 2 Imported by: 2

Documentation

Overview

Package escape provides Twig-compatible escape functions.

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func CSS

func CSS(in string) string

CSS provides a Twig-compatible CSS escaper.

Example
package main

import (
	"fmt"

	"github.com/tyler-sommer/stick/twig/escape"
)

func main() {
	input := "some \" bad content"
	fmt.Printf("div:after { content: \"%s\"; }", escape.CSS(input))
}
Output:

div:after { content: "some\0020\0022\0020bad\0020content"; }

func HTML

func HTML(in string) string

HTML provides a Twig-compatible HTML escape function.

Example
package main

import (
	"fmt"

	"github.com/tyler-sommer/stick/twig/escape"
)

func main() {
	input := "Very <unsafe> \"string & stuff'"
	fmt.Print(escape.HTML(input))
}
Output:

Very &lt;unsafe&gt; &quot;string &amp; stuff&#39;

func HTMLAttribute

func HTMLAttribute(in string) string

HTMLAttribute provides a Twig-compatible escaper for HTML attributes.

Example
package main

import (
	"fmt"

	"github.com/tyler-sommer/stick/twig/escape"
)

func main() {
	input := "a bad\">\battribute<נש"
	fmt.Printf("<a href=\"%s\">A link</a>", escape.HTMLAttribute(input))
}
Output:

<a href="a&#32;bad&quot;&gt;&#xFFFD;attribute&lt;&#1504;&#1513;">A link</a>

func JS

func JS(in string) string

JS provides a Twig-compatible javascript escaper.

Example
package main

import (
	"fmt"

	"github.com/tyler-sommer/stick/twig/escape"
)

func main() {
	input := "some \"' bad javascript"
	fmt.Printf("var test = \"%s\";", escape.JS(input))
}
Output:

var test = "some\u0020\u0022\u0027\u0020bad\u0020javascript";

func URLQueryParam

func URLQueryParam(in string) string

URLQueryParam provides Twig-compatible query string escaper.

Example
package main

import (
	"fmt"

	"github.com/tyler-sommer/stick/twig/escape"
)

func main() {
	input := "מיין מאמעם"
	fmt.Printf("?who=%s", escape.URLQueryParam(input))
}
Output:

?who=%D7%9E%D7%99%D7%99%D7%9F%20%D7%9E%D7%90%D7%9E%D7%A2%D7%9D

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL