From 4046cfb86cd0efc2c5e7d5350e3568345121d82c Mon Sep 17 00:00:00 2001 From: fangq <fangq@786e58fb-9377-0410-9ff7-e4ac0ac0635c> Date: Tue, 28 Feb 2012 19:02:09 +0000 Subject: [PATCH] loadjson quotation mark escape bug, see http://bit.ly/yyk1nS git-svn-id: http://svn.code.sf.net/p/iso2mesh/code/trunk/jsonlab@358 786e58fb-9377-0410-9ff7-e4ac0ac0635c --- examples/example3.json | 2 +- loadjson.m | 6 +++++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/examples/example3.json b/examples/example3.json index ab826af..b7ca941 100644 --- a/examples/example3.json +++ b/examples/example3.json @@ -3,7 +3,7 @@ "value": "_&File", "popup": { "menuitem": [ - {"value": "_&New", "onclick": "CreateNewDoc(\"\")"}, + {"value": "_&New", "onclick": "CreateNewDoc(\"\"\")"}, {"value": "_&Open", "onclick": "OpenDoc()"}, {"value": "_&Close", "onclick": "CloseDoc()"} ] diff --git a/loadjson.m b/loadjson.m index 8c92409..fcbaf9b 100644 --- a/loadjson.m +++ b/loadjson.m @@ -50,6 +50,10 @@ end pos = 1; len = length(string); inStr = string; isoct=exist('OCTAVE_VERSION'); arraytoken=find(inStr=='[' | inStr==']' | inStr=='"'); +jstr=inStr; +jstr=regexprep(jstr,'\\\\',' '); +escquote=regexp(jstr,'\\"'); +arraytoken=sort([arraytoken escquote]); % String delimiters and escape chars identified to improve speed: esc = find(inStr=='"' | inStr=='\' ); % comparable to: regexp(inStr, '["\\]'); @@ -452,7 +456,7 @@ while(pos<len) end pos=pos+1; end - +error('unmatched quotation mark'); %%------------------------------------------------------------------------- function [endpos e1l e1r maxlevel] = matching_bracket(str,pos) global arraytoken -- GitLab