diff --git a/py/objstr.c b/py/objstr.c index 4c09871b966f7913f2e3f1bff659b60d975a5e32..d2d672b983e68baf9319e29dd26222aaf6d07f93 100644 --- a/py/objstr.c +++ b/py/objstr.c @@ -63,7 +63,10 @@ void mp_str_print_quoted(void (*print)(void *env, const char *fmt, ...), void *e print(env, "%c", *s); } else if (*s == '\n') { print(env, "\\n"); - // TODO add more escape codes here if we want to match CPython + } else if (*s == '\r') { + print(env, "\\r"); + } else if (*s == '\t') { + print(env, "\\t"); } else { print(env, "\\x%02x", *s); } diff --git a/tests/basics/string-repr.py b/tests/basics/string-repr.py new file mode 100644 index 0000000000000000000000000000000000000000..ba8dbe6d1c6af1340c787c0d8fb92ff4bba97ec3 --- /dev/null +++ b/tests/basics/string-repr.py @@ -0,0 +1,3 @@ +# anything above 0xa0 is printed as Unicode by CPython3.3 +for c in range(0xa1): + print("0x%02x: %s" % (c, repr(chr(c))))