From bf730bb9536bd527c12686223bc74844c430a3b5 Mon Sep 17 00:00:00 2001 From: Bob Nystrom Date: Sat, 27 Jun 2015 08:11:58 -0700 Subject: [PATCH] More tests for invalid code points. --- src/vm/wren_utils.c | 1 - test/core/string/code_point_at_incomplete.wren | 9 +++++++-- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/src/vm/wren_utils.c b/src/vm/wren_utils.c index 7ed15c16..32a2b3a7 100644 --- a/src/vm/wren_utils.c +++ b/src/vm/wren_utils.c @@ -143,7 +143,6 @@ int wrenUtf8Decode(const uint8_t* bytes, uint32_t length) } // Don't read past the end of the buffer on truncated UTF-8. - // TODO: Test this. if (remainingBytes > length - 1) return -1; while (remainingBytes > 0) diff --git a/test/core/string/code_point_at_incomplete.wren b/test/core/string/code_point_at_incomplete.wren index 648ed30e..b184b1ec 100644 --- a/test/core/string/code_point_at_incomplete.wren +++ b/test/core/string/code_point_at_incomplete.wren @@ -1,3 +1,8 @@ +// The first byte of a two-octet sequence. +IO.print("\xc0".codePointAt(0)) // expect: -1 + +// The first byte of a three-octet sequence. +IO.print("\xe0".codePointAt(0)) // expect: -1 + // The first two bytes of a three-octet sequence. -var s = "\xe0\xae" -IO.print(s.codePointAt(0)) // expect: -1 +IO.print("\xe0\xae".codePointAt(0)) // expect: -1