mholt / json-to-go

Translates JSON into a Go type in your browser instantly (original)
https://mholt.github.io/json-to-go/
MIT License
4.48k stars 473 forks source link

Greedy time regex #122

Closed ejcx closed 10 months ago

ejcx commented 10 months ago

This bit me today, after years of using this site. Really amazing that this is the first bug I've hit.

let val = "my name is bob 2023-11-03T02:18:10+00:00"
if (/\d{4}-\d\d-\d\dT\d\d:\d\d:\d\d(\.\d+)?(\+\d\d:\d\d|Z)/.test(val)) {
    console.log("time.Time");
}
> time.Time

The code in question: https://github.com/mholt/json-to-go/blob/master/json-to-go.js#L324-L325

mholt commented 10 months ago

Never thought of that -- thanks for the PR. I'm surprised that's the first bug you've hit, since we have a fair number of them :sweat_smile: