diff --git a/.changeset/calm-parents-tell.md b/.changeset/calm-parents-tell.md new file mode 100644 index 000000000..67af42491 --- /dev/null +++ b/.changeset/calm-parents-tell.md @@ -0,0 +1,5 @@ +--- +'@astrojs/compiler': patch +--- + +Fixes an edge case that caused a difficult-to-reproduce panic diff --git a/internal/token.go b/internal/token.go index afae341bc..8a0531966 100644 --- a/internal/token.go +++ b/internal/token.go @@ -1248,13 +1248,14 @@ func (z *Tokenizer) readUnclosedTag() bool { var close int if z.fm == FrontmatterOpen { close = strings.Index(string(buf), "---") - if close != -1 { + if close != -1 && len(buf) < close { + buf = buf[0:close] + } + } else { + close = bytes.Index(buf, []byte{'>'}) + if close != -1 && len(buf) < close { buf = buf[0:close] } - } - close = bytes.Index(buf, []byte{'>'}) - if close != -1 { - buf = buf[0:close] } if close == -1 { // We can't find a closing tag... @@ -1878,6 +1879,14 @@ frontmatter_loop: return z.tt } + // handle string + if c == '\'' || c == '"' || c == '`' { + z.readString(c) + z.tt = TextToken + z.data.End = z.raw.End + return z.tt + } + s := z.buf[z.raw.Start : z.raw.Start+1][0] if s == '<' || s == '{' || s == '}' || c == '<' || c == '{' || c == '}' { @@ -1891,14 +1900,6 @@ frontmatter_loop: } } - // handle string - if c == '\'' || c == '"' || c == '`' { - z.readString(c) - z.tt = TextToken - z.data.End = z.raw.End - return z.tt - } - z.dashCount = 0 continue frontmatter_loop }