-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathhtml_unescape.go
30 lines (24 loc) · 884 Bytes
/
html_unescape.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
// Copyright (c) 2023-2024 Onur Cinar.
// Use of this source code is governed by a MIT-style
// license that can be found in the LICENSE file.
// https://github.com/cinar/checker
package v2
import (
"html"
"reflect"
)
// nameHTMLUnescape is the name of the HTML unescape normalizer.
const nameHTMLUnescape = "html-unescape"
// HTMLUnescape applies HTML unescaping to special characters.
func HTMLUnescape(value string) (string, error) {
return html.UnescapeString(value), nil
}
// reflectHTMLUnescape applies HTML unescaping to special characters.
func reflectHTMLUnescape(value reflect.Value) (reflect.Value, error) {
newValue, err := HTMLUnescape(value.Interface().(string))
return reflect.ValueOf(newValue), err
}
// makeHTMLUnescape returns the HTML unescape normalizer function.
func makeHTMLUnescape(_ string) CheckFunc[reflect.Value] {
return reflectHTMLUnescape
}