Skip to content

Commit

Permalink
fix: regex syntax incorrect causing hyphenated classes to be sanitize…
Browse files Browse the repository at this point in the history
…d. (#58)

When including a hyphen in a regex it must come first: [-A-Z]
  • Loading branch information
joerdav authored Sep 2, 2022
1 parent 35ba5eb commit eb9c263
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
2 changes: 1 addition & 1 deletion runtime.go
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ func (classes CSSClasses) String() string {
return sb.String()
}

var safeClassName = regexp.MustCompile(`^-?[_a-zA-Z]+[_-a-zA-Z0-9]*$`)
var safeClassName = regexp.MustCompile(`^-?[_a-zA-Z]+[-_a-zA-Z0-9]*$`)

const fallbackClassName = ConstantCSSClass("--templ-css-class-safe-name")

Expand Down
8 changes: 8 additions & 0 deletions runtime_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,14 @@ func TestClassSanitization(t *testing.T) {
input: `safe`,
expected: `safe`,
},
{
input: `safe-name`,
expected: "safe-name",
},
{
input: `safe_name`,
expected: "safe_name",
},
{
input: `!unsafe`,
expected: "--templ-css-class-safe-name",
Expand Down

0 comments on commit eb9c263

Please sign in to comment.