stacks-network / clarity-wasm

`clar2wasm` is a compiler for generating WebAssembly from Clarity.
GNU General Public License v3.0
12 stars 9 forks source link

Stdlib `$is-valid-string-ascii" does not account for all characters #389

Closed Acaccia closed 2 months ago

Acaccia commented 2 months ago

The function $stdlib.is-valid-string-ascii does not account for some whitespace characters. This causes a bug in the deserialization of strings.

Here is a test that should work:

#[test]
fn all_valid_ascii() {
    let all_chars = "\t\n\x0c\r !\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~";
    let snippet = "(from-consensus-buff? (string-ascii 256) 0x0d00000063090a0c0d202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e)";
    crosscheck(
        snippet,
        Ok(Some(Value::Sequence(SequenceData::String(ASCII(
            ASCIIData {
                data: all_chars.bytes().collect(),
            },
        ))))),
    )
}