Skip to content

🐛 BUG: Failing input to astro.ParseFragmentWithOptions #643

@jasikpark

Description

@jasikpark

What version of @astrojs/compiler are you using?

0.29.17

What package manager are you using?

pnpm

What operating system are you using?

Mac

Describe the Bug

Passing <A 0{{/}/*> to

h := handler.NewHandler(source, "FuzzScopeHTML.astro")

results in a panic:

go test ./internal/transform -run=FuzzScopeHTML/c5dd0833515e91025fce6f7774a962082d4a4b30ff94566f2d4f30d3ade9f17d
--- FAIL: FuzzScopeHTML (0.00s)
    --- FAIL: FuzzScopeHTML/c5dd0833515e91025fce6f7774a962082d4a4b30ff94566f2d4f30d3ade9f17d (0.00s)
panic: runtime error: slice bounds out of range [5:4] [recovered]
        panic: runtime error: slice bounds out of range [5:4]

goroutine 5 [running]:
testing.tRunner.func1.2({0x102a28ee0, 0x140000142a0})
        /usr/local/go/src/testing/testing.go:1396 +0x1c8
testing.tRunner.func1()
        /usr/local/go/src/testing/testing.go:1399 +0x378
panic({0x102a28ee0, 0x140000142a0})
        /usr/local/go/src/runtime/panic.go:884 +0x204
github.com/withastro/compiler/internal.(*Tokenizer).hasAttribute(...)
        /Users/calebjasik/Git/withastro/compiler/internal/token.go:985
github.com/withastro/compiler/internal.(*Tokenizer).readStartTag(0x14000003d40)
        /Users/calebjasik/Git/withastro/compiler/internal/token.go:1016 +0x7c0
github.com/withastro/compiler/internal.(*Tokenizer).Next(0x14000003d40)
        /Users/calebjasik/Git/withastro/compiler/internal/token.go:1583 +0x9a0
github.com/withastro/compiler/internal.(*parser).parse(0x140000005a0)
        /Users/calebjasik/Git/withastro/compiler/internal/parser.go:2954 +0x120
github.com/withastro/compiler/internal.ParseFragmentWithOptions({0x102a3ac38, 0x1400017e3e0}, 0x14000000480, {0x14000079598, 0x1, 0x102a03680?})
        /Users/calebjasik/Git/withastro/compiler/internal/parser.go:3093 +0x67c
github.com/withastro/compiler/internal/transform.FuzzScopeHTML.func1(0x14000003a00, {0x1400001b011, 0xb})
        /Users/calebjasik/Git/withastro/compiler/internal/transform/scope-html_test.go:137 +0x108
reflect.Value.call({0x102a03680?, 0x102a39558?, 0x13?}, {0x10298bcf3, 0x4}, {0x140001d82d0, 0x2, 0x2?})
        /usr/local/go/src/reflect/value.go:584 +0x688
reflect.Value.Call({0x102a03680?, 0x102a39558?, 0x1400006ac30?}, {0x140001d82d0?, 0x102c40108?, 0x1400001b5e0?})
        /usr/local/go/src/reflect/value.go:368 +0x90
testing.(*F).Fuzz.func1.1(0x0?)
        /usr/local/go/src/testing/fuzz.go:337 +0x1dc
testing.tRunner(0x14000003a00, 0x1400014a090)
        /usr/local/go/src/testing/testing.go:1446 +0x10c
created by testing.(*F).Fuzz.func1
        /usr/local/go/src/testing/fuzz.go:324 +0x4c4
FAIL    github.com/withastro/compiler/internal/transform        0.104s
FAIL

to replicate, checkout #619 and create a file in internal/transform/testdata/fuzz/FuzzScopeHTML/c5dd0833515e91025fce6f7774a962082d4a4b30ff94566f2d4f30d3ade9f17d with the contents

go test fuzz v1
string("<A 0{{/}/*>")

then run go test ./internal/transform -run=FuzzScopeHTML/c5dd0833515e91025fce6f7774a962082d4a4b30ff94566f2d4f30d3ade9f17d

Link to Minimal Reproducible Example

see above description (not sure this would work in stackblitz..

Metadata

Metadata

Assignees

No one assigned

    Labels

    - P3: minor bugAn edge case that only affects very specific usage (priority)

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions