|
232 | 232 | if (nargout > 1 || opt.mmaponly)
|
233 | 233 | mmap{end + 1} = {opt.jsonpath_, [pos, 0, w1]};
|
234 | 234 | [data{jsoncount}, pos, index_esc, newmmap] = parse_object(inputstr, pos, esc, index_esc, opt);
|
| 235 | + if (pos < 0) |
| 236 | + opt.usemap = 1; |
| 237 | + [data{jsoncount}, pos, index_esc, newmmap] = parse_object(inputstr, -pos, esc, index_esc, opt); |
| 238 | + end |
235 | 239 | mmap{end}{2}(2) = pos - mmap{end}{2}(1);
|
236 | 240 | mmap = [mmap(:); newmmap(:)];
|
237 | 241 | else
|
238 | 242 | [data{jsoncount}, pos, index_esc] = parse_object(inputstr, pos, esc, index_esc, opt);
|
| 243 | + if (pos < 0) |
| 244 | + opt.usemap = 1; |
| 245 | + [data{jsoncount}, pos, index_esc] = parse_object(inputstr, -pos, esc, index_esc, opt); |
| 246 | + end |
239 | 247 | end
|
240 | 248 | case '['
|
241 | 249 | if (nargout > 1 || opt.mmaponly)
|
|
536 | 544 | return
|
537 | 545 | case '{'
|
538 | 546 | [varargout{1:nargout}] = parse_object(inputstr, pos, esc, index_esc, varargin{:});
|
| 547 | + if (varargout{2} < 0) |
| 548 | + varargin{1}.usemap = 1; |
| 549 | + [varargout{1:nargout}] = parse_object(inputstr, -varargout{2}, esc, index_esc, varargin{:}); |
| 550 | + end |
539 | 551 | return
|
540 | 552 | case {'-', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9'}
|
541 | 553 | [varargout{1:2}] = parse_number(inputstr, pos, varargin{:});
|
|
563 | 575 |
|
564 | 576 | %% -------------------------------------------------------------------------
|
565 | 577 | function [object, pos, index_esc, mmap] = parse_object(inputstr, pos, esc, index_esc, varargin)
|
| 578 | +oldpos = pos; |
566 | 579 | if (nargout > 3)
|
567 | 580 | mmap = {};
|
568 | 581 | origpath = varargin{1}.jsonpath_;
|
|
578 | 591 | if cc ~= '}'
|
579 | 592 | while 1
|
580 | 593 | [str, pos, index_esc] = parseStr(inputstr, pos, esc, index_esc, varargin{:});
|
| 594 | + if (length(str) > 63) |
| 595 | + pos = -oldpos; |
| 596 | + object = []; |
| 597 | + return |
| 598 | + end |
581 | 599 | if isempty(str) && ~usemap
|
582 | 600 | str = 'x0x0_'; % empty name is valid in JSON, decodevarname('x0x0_') restores '\0'
|
583 | 601 | end
|
|
594 | 612 | if (usemap)
|
595 | 613 | object(str) = val;
|
596 | 614 | else
|
597 |
| - object.(encodevarname(str, varargin{:})) = val; |
| 615 | + str = encodevarname(str, varargin{:}); |
| 616 | + if (length(str) > 63) |
| 617 | + pos = -oldpos; |
| 618 | + object = []; |
| 619 | + return |
| 620 | + end |
| 621 | + object.(str) = val; |
598 | 622 | end
|
599 | 623 | [cc, pos] = next_char(inputstr, pos);
|
600 | 624 | if cc == '}'
|
|
0 commit comments