gobuffalo / plush

The powerful template system that Go needs
MIT License
895 stars 57 forks source link

Plush Panics when accessing a map with a key that's not comparable with the map index #176

Closed Mido-sys closed 1 year ago

Mido-sys commented 1 year ago

This code panics:

    input := `<%= m["first"]%>`
    _, err := Render(input, NewContextWith(map[string]interface{}{

        "m": map[int]bool{0: true},
    }))
panic: reflect.Value.MapIndex: value of type int is not assignable to type string

goroutine 27183 [running]:
reflect.Value.assignTo({0x1000620?, 0x1b13820?, 0xc0005348d0?}, {0x11ee87f, 0x16}, 0x10010e0, 0x0)
    /usr/local/go/src/reflect/value.go:3064 +0x2ac
reflect.Value.MapIndex({0x1049700?, 0xc000d9c540?, 0xc0008feb40?}, {0x1000620, 0x1b13820, 0x82})
    /usr/local/go/src/reflect/value.go:1609 +0xed
github.com/gobuffalo/plush/v4.(*compiler).evalAccessIndex(0x10071?, {0x1049700?, 0xc000d9c540?}, {0x1000620?, 0x1b13820?}, 0xc0004f87e0)
    /home/------/----/pkg/mod/github.com/gobuffalo/plush/v4@v4.1.17/compiler.go:323 +0x18a
Mido-sys commented 1 year ago

@sio4 @paganotoni , I sent a PR to fix this issue. Kindly check the pull request. We discovered that bug and hope to get the PR merged :)

Mido-sys commented 1 year ago

@paganotoni Thank you :)