Skip to content

Commit

Permalink
Take key length (#105)
Browse files Browse the repository at this point in the history
* Checking for raw attr, check key-length

* Adds a test

* Make sure both are less than...

* Adds a changeset
  • Loading branch information
matthewp authored Oct 25, 2021
1 parent aa188e7 commit 2f4b772
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .changeset/rotten-years-warn.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@astrojs/compiler': patch
---

Prevents overrunning an array when checking for raw attribute
3 changes: 2 additions & 1 deletion internal/token.go
Original file line number Diff line number Diff line change
Expand Up @@ -935,9 +935,10 @@ loop:
func (z *Tokenizer) hasTag(s string) bool {
loop:
for i := len(z.attr) - 1; i >= 0; i-- {

x := z.attr[i]
key := z.buf[x[0].Start:x[0].End]
for i := 0; i < len(s); i++ {
for i := 0; i < len(key) && i < len(s); i++ {
c := key[i]
if 'A' <= c && c <= 'Z' {
c += 'a' - 'A'
Expand Down
5 changes: 5 additions & 0 deletions internal/token_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,11 @@ func TestBasic(t *testing.T) {
"<span data-astro-raw>function foo() { }</span>",
[]TokenType{StartTagToken, TextToken, EndTagToken},
},
{
"Doesn't throw on other data attributes",
"<span data-foo></span>",
[]TokenType{StartTagToken, EndTagToken},
},
}

runTokenTypeTest(t, Basic)
Expand Down

0 comments on commit 2f4b772

Please sign in to comment.