Ph0enixKM / Amber

💎 Amber the programming language compiled to bash
https://amber-lang.com
GNU General Public License v3.0
3.54k stars 70 forks source link

🐞 `includes` function in standard library incorrect (false positives) #118

Closed jemma-nelson closed 4 weeks ago

jemma-nelson commented 1 month ago

https://github.com/Ph0enixKM/Amber/blob/master/src/std/main.ab#L109-L112

The implementation of includes here seems like it likely does not match designer intent. It ends up producing bash code like: [[ "${arr[@]}" =~ "${value}" ]]. Using as example values of arr = ["foo", "bar", "baz"] and value = "oo ba", this becomes [[ "foo bar baz" =~ "oo ba" ]] after parameter expansion, which returns 0 (true).

The sensible implementation is likely iterating over the array and testing each element, returning early if you find a match.

Ph0enixKM commented 1 month ago

We have to also add tests to prevent this bug in the future