marvindv / jsonlogic_rs

A JsonLogic implementation in Rust
MIT License
5 stars 3 forks source link

substr index calculation does not match JavaScript implementation #12

Open panzi opened 3 years ago

panzi commented 3 years ago

Just by reviewing the code (haven't actually ran it) I'm pretty sure this library from suffers the same bugs as I've reported to another JsonLogic Rust implementation (except for the type coercion, which seems to be done right here): https://github.com/Bestowinc/json-logic-rs/issues/27

Long story short: The indices are supposed to operate on UTF-16 surrogate pairs, but in this library they act on full code points, and furthermore String::len() is used at some point which returns the number of bytes as encoded by UTF-8 and as such negative indices on any non-ASCII strings are broken (internally inconsistent).

marvindv commented 3 years ago

Thank you for letting me know, I will have a look into it as soon as i can.