use text/template to avoid HTML escaping
Co-authored-by: Roy O'Young <roy2220@outlook.com> Closes #57
This commit is contained in:
2
main.go
2
main.go
@@ -21,13 +21,13 @@ import (
|
|||||||
"errors"
|
"errors"
|
||||||
"flag"
|
"flag"
|
||||||
"fmt"
|
"fmt"
|
||||||
"html/template"
|
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"log"
|
"log"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"regexp"
|
"regexp"
|
||||||
"strings"
|
"strings"
|
||||||
|
"text/template"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"golang.org/x/sync/errgroup"
|
"golang.org/x/sync/errgroup"
|
||||||
|
|||||||
@@ -15,13 +15,13 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"html/template"
|
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"os"
|
"os"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"strings"
|
"strings"
|
||||||
"testing"
|
"testing"
|
||||||
|
"text/template"
|
||||||
)
|
)
|
||||||
|
|
||||||
func run(t *testing.T, name string, args ...string) {
|
func run(t *testing.T, name string, args ...string) {
|
||||||
|
|||||||
2
tmpl.go
2
tmpl.go
@@ -18,9 +18,9 @@ import (
|
|||||||
"bufio"
|
"bufio"
|
||||||
"bytes"
|
"bytes"
|
||||||
"fmt"
|
"fmt"
|
||||||
"html/template"
|
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"strings"
|
"strings"
|
||||||
|
"text/template"
|
||||||
"unicode"
|
"unicode"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
10
tmpl_test.go
10
tmpl_test.go
@@ -16,9 +16,9 @@ package main
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
"html/template"
|
|
||||||
"os"
|
"os"
|
||||||
"testing"
|
"testing"
|
||||||
|
"text/template"
|
||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
@@ -170,6 +170,14 @@ func TestExecuteTemplate(t *testing.T) {
|
|||||||
"/*", " * ", "*/",
|
"/*", " * ", "*/",
|
||||||
"/*\n * HYS\n*/\n\n",
|
"/*\n * HYS\n*/\n\n",
|
||||||
},
|
},
|
||||||
|
|
||||||
|
// ensure we don't escape HTML characters by using the wrong template package
|
||||||
|
{
|
||||||
|
"{{.Holder}}",
|
||||||
|
licenseData{Holder: "A&Z"},
|
||||||
|
"", "", "",
|
||||||
|
"A&Z\n\n",
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, tt := range tests {
|
for _, tt := range tests {
|
||||||
|
|||||||
Reference in New Issue
Block a user