diff --git a/platforms/app/main.c b/platforms/app/main.c index 0352aa5..e77c276 100644 --- a/platforms/app/main.c +++ b/platforms/app/main.c @@ -80,7 +80,24 @@ M3Result repl_init(IM3Environment env, IM3Runtime* runtime) return c_m3Err_none; } -int split_argv(char *str, const char** argv) +static +void unescape(char* buff) +{ + char* outp = buff; + while (*buff) { + if (*buff == '\\' && *(buff+1) == 'x') { + char hex[3] = { *(buff+2), *(buff+3), '\0' }; + *outp++ = strtol(hex, NULL, 16); + buff += 4; + } else { + *outp++ = *buff++; + } + } + *outp = '\0'; +} + +static +int split_argv(char *str, char** argv) { int result = 0; char* curr = str; @@ -185,8 +202,8 @@ int main (int i_argc, const char* i_argv[]) while (argRepl) { - char cmd_buff[256] = { 0, }; - const char* argv[32] = { 0, }; + char cmd_buff[1024] = { 0, }; + char* argv[32] = { 0, }; fprintf(stdout, "wasm3> "); fflush(stdout); if (!fgets(cmd_buff, sizeof(cmd_buff), stdin)) { @@ -207,6 +224,7 @@ int main (int i_argc, const char* i_argv[]) } else if (argv[0][0] == ':') { result = "no such command"; } else { + unescape(argv[0]); result = repl_call(runtime, argv[0], argc-1, argv+1); } diff --git a/test/run-spec-test.py b/test/run-spec-test.py index 57ae089..d7be26a 100755 --- a/test/run-spec-test.py +++ b/test/run-spec-test.py @@ -14,7 +14,7 @@ # - Get more tests from: https://github.com/microsoft/ChakraCore/tree/master/test/WasmSpec # - Fix "Empty Stack" check # - Check Canonical NaN and Arithmetic NaN separately -# - Fix names.wast, imports.wast +# - Fix imports.wast import argparse import os, sys, glob, time @@ -102,6 +102,24 @@ def binaryToFloat(num, t): else: fatal(f"Unknown type '{t}'") +def escape(s): + c = ord(s) + + if c < 128 and s.isprintable() and not s in " \n\r\t\\": + return s + + if c <= 0xff: + return r'\x{0:02x}'.format(c) + elif c <= 0xffff: + return r'\u{0:04x}'.format(c) + else: + return r'\U{0:08x}'.format(c) + +def escape_str(s): + if s == "": + return r'\x00' + return ''.join(escape(c) for c in s) + # # Value format options # @@ -320,7 +338,7 @@ blacklist = Blacklist([ "*.wast:* *.wasm print32*", "*.wast:* *.wasm print64*", "imports.wast:*", - "names.wast:*", + "names.wast:630 *", # name that starts with '\0' ]) stats = dotdict(total_run=0, skipped=0, failed=0, crashed=0, timeout=0, success=0, missing=0) @@ -523,6 +541,8 @@ for fn in jsonFiles: warning(f"Skipped {test.source} (invoke in module)") continue + test.action.field = escape_str(test.action.field) + runInvoke(test) else: stats.skipped += 1