From c43a758a01f56c7d7448f01620ed2f0d03a42299 Mon Sep 17 00:00:00 2001 From: Qianqian Fang Date: Thu, 11 Jan 2024 18:53:12 -0500 Subject: [PATCH] [bug] fix missing index_esc reset, add test for automap --- loadjson.m | 3 +++ test/run_jsonlab_test.m | 2 ++ 2 files changed, 5 insertions(+) diff --git a/loadjson.m b/loadjson.m index 5d55d69..8bf5f57 100644 --- a/loadjson.m +++ b/loadjson.m @@ -576,6 +576,7 @@ %% ------------------------------------------------------------------------- function [object, pos, index_esc, mmap] = parse_object(inputstr, pos, esc, index_esc, varargin) oldpos = pos; +oldindex_esc = index_esc; if (nargout > 3) mmap = {}; origpath = varargin{1}.jsonpath_; @@ -593,6 +594,7 @@ [str, pos, index_esc] = parseStr(inputstr, pos, esc, index_esc, varargin{:}); if (length(str) > 63) pos = -oldpos; + index_esc = oldindex_esc; object = []; return end @@ -615,6 +617,7 @@ str = encodevarname(str, varargin{:}); if (length(str) > 63) pos = -oldpos; + index_esc = oldindex_esc; object = []; return end diff --git a/test/run_jsonlab_test.m b/test/run_jsonlab_test.m index e131b1f..7bd6246 100644 --- a/test/run_jsonlab_test.m +++ b/test/run_jsonlab_test.m @@ -59,6 +59,7 @@ function run_jsonlab_test(tests) test_jsonlab('empty name with map', @savejson, loadjson('{"":""}', 'usemap', 1), '{"":""}', 'compact', 1); test_jsonlab('indentation', @savejson, savejson('s', containers.Map({'a', 'b'}, {[], struct('c', 1.1, 'd', struct('e', {1, 2}))})), ... '"{\n\t\"s\":{\n\t\t\"a\":[],\n\t\t\"b\":{\n\t\t\t\"c\":1.1,\n\t\t\t\"d\":[\n\t\t\t\t{\n\t\t\t\t\t\"e\":1\n\t\t\t\t},\n\t\t\t\t{\n\t\t\t\t\t\"e\":2\n\t\t\t\t}\n\t\t\t]\n\t\t}\n\t}\n}\n"'); + test_jsonlab('key longer than 63', @savejson, loadjson('{"...........":""}', 'usemap', 0), '{"...........":""}', 'compact', 1); end test_jsonlab('row vector', @savejson, [1, 2, 3], '[1,2,3]'); test_jsonlab('column vector', @savejson, [1; 2; 3], '[[1],[2],[3]]', 'compact', 1); @@ -200,6 +201,7 @@ function run_jsonlab_test(tests) test_jsonlab('empty name', @savebj, loadbj(['{U' 0 'U' 2 '}']), '{U<0>U<2>}', 'debug', 1); if (exist('containers.Map')) test_jsonlab('empty name with map', @savebj, loadbj(['{U' 0 'U' 2 '}'], 'usemap', 1), '{U<0>U<2>}', 'debug', 1); + test_jsonlab('key longer than 63', @savebj, loadbj(['{U' 11 '...........U' 2 '}'], 'usemap', 0), '{U<11>...........U<2>}', 'debug', 1); end test_jsonlab('row vector', @savebj, [1, 2, 3], '[$U#U<3><1><2><3>', 'debug', 1); test_jsonlab('column vector', @savebj, [1; 2; 3], '[$U#[$U#U<2><3><1><1><2><3>', 'debug', 1);