From ee7b34166fcfc7bef1a32e33931f754f3747a118 Mon Sep 17 00:00:00 2001 From: Marc Gurevitx Date: Tue, 11 Jun 2024 00:48:20 +0300 Subject: [PATCH] Return null from utf8 if len == 0 --- MiniScript-cpp/rdTest.ms | 7 +++++++ MiniScript-cpp/src/ShellIntrinsics.cpp | 3 +++ 2 files changed, 10 insertions(+) diff --git a/MiniScript-cpp/rdTest.ms b/MiniScript-cpp/rdTest.ms index 085a5f5..3ffee10 100644 --- a/MiniScript-cpp/rdTest.ms +++ b/MiniScript-cpp/rdTest.ms @@ -65,4 +65,11 @@ testRawData = function r.setUtf8 0, "hello world" qa.assertEqual r.utf8(0), "hello w" + r = new RawData + qa.assertEqual r.utf8, null + r.resize 0 + qa.assertEqual r.utf8, null + r.resize + r.resize 0 + qa.assertEqual r.utf8, null end function diff --git a/MiniScript-cpp/src/ShellIntrinsics.cpp b/MiniScript-cpp/src/ShellIntrinsics.cpp index ecf68e4..d266a77 100644 --- a/MiniScript-cpp/src/ShellIntrinsics.cpp +++ b/MiniScript-cpp/src/ShellIntrinsics.cpp @@ -1112,6 +1112,9 @@ static IntrinsicResult intrinsic_rawDataUtf8(Context *context, IntrinsicResult p long nBytes = context->GetVar("bytes").IntValue(); const char *data = (const char *)rawDataGetBytes(self, offset, nBytes, rdnaNull); if (!data) return IntrinsicResult::Null; + Value dataWrapper = self.Lookup(_handle); + RawDataHandleStorage *storage = (RawDataHandleStorage*)dataWrapper.data.ref; + if (storage->dataSize == 0) return IntrinsicResult::Null; String result(data, nBytes); return IntrinsicResult(result); }