Skip to content

Commit feaced6

Browse files
committed
[bug] escape . in the jsonpath tracking
1 parent 8846515 commit feaced6

File tree

1 file changed

+11
-9
lines changed

1 file changed

+11
-9
lines changed

jdict.m

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -231,10 +231,10 @@
231231
continue
232232
end
233233
end
234-
234+
escapedonekey = regexprep(onekey, '(?<=[^\\]|^)\.', '\\.');
235235
if (ischar(onekey) && ~isempty(onekey) && onekey(1) == char(36))
236236
val = obj.call_('jsonpath', val, onekey);
237-
trackpath = onekey;
237+
trackpath = escapedonekey;
238238
elseif (isstruct(val))
239239
% check if struct array - if so, get field from all elements
240240
if (numel(val) > 1 && isfield(val, onekey))
@@ -248,7 +248,7 @@
248248
% keep as cell if concatenation fails
249249
end
250250
end
251-
trackpath = [trackpath '.' onekey];
251+
trackpath = [trackpath '.' escapedonekey];
252252
% check if next operation is () for indexing the result
253253
if (i < oplen && strcmp(idxkey(i + 1).type, '()') && ~isempty(idxkey(i + 1).subs))
254254
subsargs = struct('type', '()', 'subs', idxkey(i + 1).subs);
@@ -259,11 +259,11 @@
259259
else
260260
% single struct or scalar field access
261261
val = val.(onekey);
262-
trackpath = [trackpath '.' onekey];
262+
trackpath = [trackpath '.' escapedonekey];
263263
end
264264
elseif (isa(val, 'containers.Map') || isa(val, 'dictionary'))
265265
val = val(onekey);
266-
trackpath = [trackpath '.' onekey];
266+
trackpath = [trackpath '.' escapedonekey];
267267
else
268268
error('key name "%s" not found', onekey);
269269
end
@@ -322,11 +322,12 @@
322322
else
323323
onekey = idx.subs;
324324
end
325+
escapedonekey = regexprep(onekey, '(?<=[^\\]|^)\.', '\\.');
325326
if (ischar(onekey) && ~isempty(onekey))
326327
if (onekey(1) ~= char(36))
327-
temppath = [temppath '.' onekey];
328+
temppath = [temppath '.' escapedonekey];
328329
else
329-
temppath = onekey;
330+
temppath = escapedonekey;
330331
end
331332
end
332333
end
@@ -353,11 +354,12 @@
353354
else
354355
onekey = idx.subs;
355356
end
357+
escapedonekey = regexprep(onekey, '(?<=[^\\]|^)\.', '\\.');
356358
if (ischar(onekey) && ~isempty(onekey))
357359
if (onekey(1) ~= char(36))
358-
temppath = [temppath '.' onekey];
360+
temppath = [temppath '.' escapedonekey];
359361
else
360-
temppath = onekey;
362+
temppath = escapedonekey;
361363
end
362364
end
363365
end

0 commit comments

Comments
 (0)