DZakh / rescript-schema

🧬 The fastest parser in the entire JavaScript ecosystem with a focus on small bundle size and top-notch DX
MIT License
146 stars 7 forks source link

Incorrect parsing with S.object + S.nullable + S.refine #79

Closed cknitt closed 1 month ago

cknitt commented 2 months ago

The following seems to be a regression in rescript-schema 7 + 8. It works fine in rescript-schema 6.

let jsonString = `{"myField": "test"}`

let schema = S.object(s => s.field("myField", S.option(S.string)))->S.refine(_ => _ => ())
// ✅ { TAG: 'Ok', _0: 'test' }
Console.log(S.parseJsonStringWith(jsonString, schema))

let schema = S.object(s => s.field("myField", S.nullable(S.string)))->S.refine(_ => _ => ())
// 😱 { TAG: 'Ok', _0: undefined }
Console.log(S.parseJsonStringWith(jsonString, schema))
DZakh commented 2 months ago

😳

DZakh commented 2 months ago

I've found the issue. I'll take a look at how I can change the core of the library to prevent this kind of error in the future. Probably release a fix this weekends. Have big workload next two days.

cknitt commented 2 months ago

I've found the issue. I'll take a look at how I can change the core of the library to prevent this kind of error in the future. Probably release a fix this weekends. Have big workload next two days.

Sorry for keeping you busy all the time 🙈. Thanks for the great work!

DZakh commented 2 months ago

Thank you for finding loopholes in my tests. There are almost a 1k of them, but that's still not enough 😅

DZakh commented 1 month ago

https://github.com/DZakh/rescript-schema/releases/tag/v8.0.1 with a fix is published. Thank you for reporting