},
{
"jsRe",
- "<button onclick='alert("{{.H}}")'>",
- `<button onclick='alert("\x3cHello\x3e")'>`,
+ `<button onclick='alert(/{{"foo+bar"}}/.test(""))'>`,
+ `<button onclick='alert(/foo\x2bbar/.test(""))'>`,
+ },
+ {
+ "jsReBlank",
+ `<script>alert(/{{""}}/.test(""));</script>`,
+ `<script>alert(/(?:)/.test(""));</script>`,
},
{
"styleBidiKeywordPassed",
// expression literal. /foo{{.X}}bar/ matches the string "foo" followed by
// the literal text of {{.X}} followed by the string "bar".
func jsRegexpEscaper(args ...interface{}) string {
- return replace(stringify(args...), jsRegexpReplacementTable)
+ s := replace(stringify(args...), jsRegexpReplacementTable)
+ if s == "" {
+ // /{{.X}}/ should not produce a line comment when .X == "".
+ return "(?:)"
+ }
+ return s
}
// stringify is an optimized form of fmt.Sprint.