diff --git a/packages/builtin/string.pony b/packages/builtin/string.pony index f5c9239ad0..204d3f0674 100644 --- a/packages/builtin/string.pony +++ b/packages/builtin/string.pony @@ -376,7 +376,7 @@ actor Main which may be present earlier in the content of the string. If you need a null-terminated copy of this string, use the clone method. """ - (_alloc > 0) and (_ptr._apply(_size) == 0) + (_alloc > 0) and (_alloc != _size) and (_ptr._apply(_size) == 0) fun utf32(offset: ISize): (U32, U8) ? => """ diff --git a/packages/builtin_test/_test.pony b/packages/builtin_test/_test.pony index 34db5e627a..542dd59338 100644 --- a/packages/builtin_test/_test.pony +++ b/packages/builtin_test/_test.pony @@ -437,6 +437,13 @@ class iso _TestStringIsNullTerminated is UnitTest h.assert_true("0123456".trim(2, 4).clone().is_null_terminated()) h.assert_false("0123456".trim(2, 4).is_null_terminated()) + h.assert_true(String.from_iso_array(recover + ['a', 'b', 'c'] + end).is_null_terminated()) + h.assert_false(String.from_iso_array(recover + ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h'] // power of two sized array + end).is_null_terminated()) + class iso _TestSpecialValuesF32 is UnitTest """