From 46bba7dc03a87e51c8029366234b2044b359b311 Mon Sep 17 00:00:00 2001 From: Ayumi Hamasaki <46076483+ayumihamasaki2@users.noreply.github.com> Date: Tue, 6 Aug 2019 13:19:14 +0100 Subject: [PATCH 1/9] Add a small JSON Parser to October framework lib --- .../assets/js/october.relation.js | 2 +- .../widgets/form/assets/js/october.form.js | 2 +- modules/system/assets/js/framework-min.js | 2 +- .../assets/js/framework.combined-min.js | 4 +- .../system/assets/js/framework.combined.js | 1 + modules/system/assets/js/framework.extras.js | 354 ++++++++++++++++++ modules/system/assets/js/framework.js | 5 +- modules/system/assets/js/october.parser.js | 353 +++++++++++++++++ modules/system/assets/ui/js/autocomplete.js | 2 +- modules/system/assets/ui/js/chart.line.js | 2 +- modules/system/assets/ui/js/popup.js | 2 +- 11 files changed, 720 insertions(+), 9 deletions(-) create mode 100644 modules/system/assets/js/october.parser.js diff --git a/modules/backend/behaviors/relationcontroller/assets/js/october.relation.js b/modules/backend/behaviors/relationcontroller/assets/js/october.relation.js index 80bf1bea4e..b5123ed001 100644 --- a/modules/backend/behaviors/relationcontroller/assets/js/october.relation.js +++ b/modules/backend/behaviors/relationcontroller/assets/js/october.relation.js @@ -87,7 +87,7 @@ if (typeof value == 'object') return value try { - return JSON.parse(JSON.stringify(eval("({" + value + "})"))) + return octoberJSON.parse("{" + value + "}") } catch (e) { throw new Error('Error parsing the '+name+' attribute value. '+e) diff --git a/modules/backend/widgets/form/assets/js/october.form.js b/modules/backend/widgets/form/assets/js/october.form.js index 0936d2df35..237f12d2b5 100644 --- a/modules/backend/widgets/form/assets/js/october.form.js +++ b/modules/backend/widgets/form/assets/js/october.form.js @@ -264,7 +264,7 @@ if (typeof value == 'object') return value try { - return JSON.parse(JSON.stringify(eval("({" + value + "})"))) + return octoberJSON.parse("{" + value + "}") } catch (e) { throw new Error('Error parsing the '+name+' attribute value. '+e) diff --git a/modules/system/assets/js/framework-min.js b/modules/system/assets/js/framework-min.js index 94fa3dc967..d099053d3e 100644 --- a/modules/system/assets/js/framework-min.js +++ b/modules/system/assets/js/framework-min.js @@ -1,4 +1,4 @@ - +"use strict";!function(){function a(e,r,n){for(var t="",o=r;o= "0" && str[pos] <= "9")) { + var body = ""; + for (var i = pos; i < str.length; i++) { + if (str[i] === "-" || str[i] === "+" || str[i] === "." || (str[i] >= "0" && str[i] <= "9")) { + body += str[i]; + } else { + return { + originLength: body.length, + body: body + }; + } + } + throw new Error("Broken JSON number body near " + body); + } + + // parse object + if (str[pos] === "{" || str[pos] === "[") { + var stack = [str[pos]]; + var body = str[pos]; + for (var i = pos + 1; i < str.length; i++) { + body += str[i]; + if (str[i] === "\\") { + if (i + 1 < str.length) body += str[i + 1]; + i++; + } else if (str[i] === "\"") { + if (stack[stack.length - 1] === "\"") { + stack.pop(); + } else if (stack[stack.length - 1] !== "'") { + stack.push(str[i]); + } + } else if (str[i] === "'") { + if (stack[stack.length - 1] === "'") { + stack.pop(); + } else if (stack[stack.length - 1] !== "\"") { + stack.push(str[i]); + } + } else if (stack[stack.length - 1] !== "\"" && stack[stack.length - 1] !== "'") { + if (str[i] === "{") { + stack.push("{"); + } else if (str[i] === "}") { + if (stack[stack.length - 1] === "{") { + stack.pop(); + } else { + throw new Error("Broken JSON " + (str[pos] === "{" ? "object" : "array") + " body near " + body); + } + } else if (str[i] === "[") { + stack.push("["); + } else if (str[i] === "]") { + if (stack[stack.length - 1] === "[") { + stack.pop(); + } else { + throw new Error("Broken JSON " + (str[pos] === "{" ? "object" : "array") + " body near " + body); + } + } + } + if (!stack.length) { + return { + originLength: i - pos, + body: body + }; + } + } + throw new Error("Broken JSON " + (str[pos] === "{" ? "object" : "array") + " body near " + body); + } + throw new Error("Broken JSON body near " + str.substr((pos - 5 >= 0) ? pos - 5 : 0, 50)); + } + + /* + * This is a char can be key head + * @param ch + * @returns {boolean} + */ + function canBeKeyHead(ch) { + if (ch[0] === "\\") return false; + if ((ch[0] >= 'a' && ch[0] <= 'z') || (ch[0] >= 'A' && ch[0] <= 'Z') || ch[0] === '_') return true; + if (ch[0] >= '0' && ch[0] <= '9') return true; + if (ch[0] === '$') return true; + if (ch.charCodeAt(0) > 255) return true; + return false; + } + + function isBlankChar(ch) { + return ch === " " || ch === "\n" || ch === "\t"; + } + + /* + * parse JSON + * @param str + */ + function parse(str) { + str = str.trim(); + if (!str.length) throw new Error("Broken JSON object."); + var result = ""; + + /* + * the mistake ',' + */ + while (str && str[0] === ",") { + str = str.substr(1); + } + + /* + * string + */ + if (str[0] === "\"" || str[0] === "'") { + if (str[str.length - 1] !== str[0]) { + throw new Error("Invalid string JSON object."); + } + + var body = "\""; + for (var i = 1; i < str.length; i++) { + if (str[i] === "\\") { + if (str[i + 1] === "'") { + body += str[i + 1] + } else { + body += str[i]; + body += str[i + 1]; + } + i++; + } else if (str[i] === str[0]) { + body += "\""; + return body + } else if (str[i] === "\"") { + body += "\\\"" + } else body += str[i]; + } + throw new Error("Invalid string JSON object."); + } + + /* + * boolean + */ + if (str === "true" || str === "false") { + return str; + } + + /* + * null + */ + if (str === "null") { + return "null"; + } + + /* + * number + */ + var num = parseFloat(str); + if (!isNaN(num)) { + return num.toString(); + } + + /* + * object + */ + if (str[0] === "{") { + var type = "needKey"; + var result = "{"; + + for (var i = 1; i < str.length; i++) { + if (isBlankChar(str[i])) { + continue; + } else if (type === "needKey" && (str[i] === "\"" || str[i] === "'")) { + var key = parseKey(str, i + 1, str[i]); + result += "\"" + key + "\""; + i += key.length; + i += 1; + type = "afterKey"; + } else if (type === "needKey" && canBeKeyHead(str[i])) { + var key = parseKey(str, i); + result += "\""; + result += key; + result += "\""; + i += key.length - 1; + type = "afterKey"; + } else if (type === "afterKey" && str[i] === ":") { + result += ":"; + type = ":"; + } else if (type === ":") { + var body = getBody(str, i); + + i = i + body.originLength - 1; + result += parse(body.body); + + type = "afterBody"; + } else if (type === "afterBody" || type === "needKey") { + var last = i; + while (str[last] === "," || isBlankChar(str[last])) { + last++; + } + if (str[last] === "}" && last === str.length - 1) { + while (result[result.length - 1] === ",") { + result = result.substr(0, result.length - 1); + } + result += "}"; + return result; + } else if (last !== i && result !== "{") { + result += ","; + type = "needKey"; + i = last - 1; + } + } + } + throw new Error("Broken JSON object near " + result); + } + + /* + * array + */ + if (str[0] === "[") { + var result = "["; + var type = "needBody"; + for (var i = 1; i < str.length; i++) { + if (" " === str[i] || "\n" === str[i] || "\t" === str[i]) { + continue; + } else if (type === "needBody") { + if (str[i] === ",") { + result += "null,"; + continue; + } + if (str[i] === "]" && i === str.length - 1) { + if (result[result.length - 1] === ",") result = result.substr(0, result.length - 1); + result += "]"; + return result; + } + + var body = getBody(str, i); + + i = i + body.originLength - 1; + result += parse(body.body); + + type = "afterBody"; + } else if (type === "afterBody") { + if (str[i] === ",") { + result += ","; + type = "needBody"; + + // deal with mistake "," + while (str[i + 1] === "," || isBlankChar(str[i + 1])) { + if (str[i + 1] === ",") result += "null,"; + i++; + } + } else if (str[i] === "]" && i === str.length - 1) { + result += "]"; + return result; + } + } + } + throw new Error("Broken JSON array near " + result); + } + } + + var g = (typeof exports === "undefined") ? (window.octoberJSON = {}) : exports; + + /* + * parse October JSON string into JSON object + * @param json + * @returns {*} + */ + g.parse = function(json) { + var jsonString = parse(json); + return JSON.parse(jsonString); + }; +})(); + +function ($) { "use strict"; if ($.oc === undefined) $.oc = {} diff --git a/modules/system/assets/js/framework.js b/modules/system/assets/js/framework.js index 4330d18be3..bfc7aaf4af 100644 --- a/modules/system/assets/js/framework.js +++ b/modules/system/assets/js/framework.js @@ -5,6 +5,9 @@ * Copyright 2017 Alexey Bobkov, Samuel Georges * ======================================================================== */ +/* October CMS JSON Parser */ +"use strict";!function(){function a(e,r,n){for(var t="",o=r;o= "0" && str[pos] <= "9")) { + var body = ""; + for (var i = pos; i < str.length; i++) { + if (str[i] === "-" || str[i] === "+" || str[i] === "." || (str[i] >= "0" && str[i] <= "9")) { + body += str[i]; + } else { + return { + originLength: body.length, + body: body + }; + } + } + throw new Error("Broken JSON number body near " + body); + } + + // parse object + if (str[pos] === "{" || str[pos] === "[") { + var stack = [str[pos]]; + var body = str[pos]; + for (var i = pos + 1; i < str.length; i++) { + body += str[i]; + if (str[i] === "\\") { + if (i + 1 < str.length) body += str[i + 1]; + i++; + } else if (str[i] === "\"") { + if (stack[stack.length - 1] === "\"") { + stack.pop(); + } else if (stack[stack.length - 1] !== "'") { + stack.push(str[i]); + } + } else if (str[i] === "'") { + if (stack[stack.length - 1] === "'") { + stack.pop(); + } else if (stack[stack.length - 1] !== "\"") { + stack.push(str[i]); + } + } else if (stack[stack.length - 1] !== "\"" && stack[stack.length - 1] !== "'") { + if (str[i] === "{") { + stack.push("{"); + } else if (str[i] === "}") { + if (stack[stack.length - 1] === "{") { + stack.pop(); + } else { + throw new Error("Broken JSON " + (str[pos] === "{" ? "object" : "array") + " body near " + body); + } + } else if (str[i] === "[") { + stack.push("["); + } else if (str[i] === "]") { + if (stack[stack.length - 1] === "[") { + stack.pop(); + } else { + throw new Error("Broken JSON " + (str[pos] === "{" ? "object" : "array") + " body near " + body); + } + } + } + if (!stack.length) { + return { + originLength: i - pos, + body: body + }; + } + } + throw new Error("Broken JSON " + (str[pos] === "{" ? "object" : "array") + " body near " + body); + } + throw new Error("Broken JSON body near " + str.substr((pos - 5 >= 0) ? pos - 5 : 0, 50)); + } + + /* + * This is a char can be key head + * @param ch + * @returns {boolean} + */ + function canBeKeyHead(ch) { + if (ch[0] === "\\") return false; + if ((ch[0] >= 'a' && ch[0] <= 'z') || (ch[0] >= 'A' && ch[0] <= 'Z') || ch[0] === '_') return true; + if (ch[0] >= '0' && ch[0] <= '9') return true; + if (ch[0] === '$') return true; + if (ch.charCodeAt(0) > 255) return true; + return false; + } + + function isBlankChar(ch) { + return ch === " " || ch === "\n" || ch === "\t"; + } + + /* + * parse JSON + * @param str + */ + function parse(str) { + str = str.trim(); + if (!str.length) throw new Error("Broken JSON object."); + var result = ""; + + /* + * the mistake ',' + */ + while (str && str[0] === ",") { + str = str.substr(1); + } + + /* + * string + */ + if (str[0] === "\"" || str[0] === "'") { + if (str[str.length - 1] !== str[0]) { + throw new Error("Invalid string JSON object."); + } + + var body = "\""; + for (var i = 1; i < str.length; i++) { + if (str[i] === "\\") { + if (str[i + 1] === "'") { + body += str[i + 1] + } else { + body += str[i]; + body += str[i + 1]; + } + i++; + } else if (str[i] === str[0]) { + body += "\""; + return body + } else if (str[i] === "\"") { + body += "\\\"" + } else body += str[i]; + } + throw new Error("Invalid string JSON object."); + } + + /* + * boolean + */ + if (str === "true" || str === "false") { + return str; + } + + /* + * null + */ + if (str === "null") { + return "null"; + } + + /* + * number + */ + var num = parseFloat(str); + if (!isNaN(num)) { + return num.toString(); + } + + /* + * object + */ + if (str[0] === "{") { + var type = "needKey"; + var result = "{"; + + for (var i = 1; i < str.length; i++) { + if (isBlankChar(str[i])) { + continue; + } else if (type === "needKey" && (str[i] === "\"" || str[i] === "'")) { + var key = parseKey(str, i + 1, str[i]); + result += "\"" + key + "\""; + i += key.length; + i += 1; + type = "afterKey"; + } else if (type === "needKey" && canBeKeyHead(str[i])) { + var key = parseKey(str, i); + result += "\""; + result += key; + result += "\""; + i += key.length - 1; + type = "afterKey"; + } else if (type === "afterKey" && str[i] === ":") { + result += ":"; + type = ":"; + } else if (type === ":") { + var body = getBody(str, i); + + i = i + body.originLength - 1; + result += parse(body.body); + + type = "afterBody"; + } else if (type === "afterBody" || type === "needKey") { + var last = i; + while (str[last] === "," || isBlankChar(str[last])) { + last++; + } + if (str[last] === "}" && last === str.length - 1) { + while (result[result.length - 1] === ",") { + result = result.substr(0, result.length - 1); + } + result += "}"; + return result; + } else if (last !== i && result !== "{") { + result += ","; + type = "needKey"; + i = last - 1; + } + } + } + throw new Error("Broken JSON object near " + result); + } + + /* + * array + */ + if (str[0] === "[") { + var result = "["; + var type = "needBody"; + for (var i = 1; i < str.length; i++) { + if (" " === str[i] || "\n" === str[i] || "\t" === str[i]) { + continue; + } else if (type === "needBody") { + if (str[i] === ",") { + result += "null,"; + continue; + } + if (str[i] === "]" && i === str.length - 1) { + if (result[result.length - 1] === ",") result = result.substr(0, result.length - 1); + result += "]"; + return result; + } + + var body = getBody(str, i); + + i = i + body.originLength - 1; + result += parse(body.body); + + type = "afterBody"; + } else if (type === "afterBody") { + if (str[i] === ",") { + result += ","; + type = "needBody"; + + // deal with mistake "," + while (str[i + 1] === "," || isBlankChar(str[i + 1])) { + if (str[i + 1] === ",") result += "null,"; + i++; + } + } else if (str[i] === "]" && i === str.length - 1) { + result += "]"; + return result; + } + } + } + throw new Error("Broken JSON array near " + result); + } + } + + var g = (typeof exports === "undefined") ? (window.octoberJSON = {}) : exports; + + /* + * parse October JSON string into JSON object + * @param json + * @returns {*} + */ + g.parse = function(json) { + var jsonString = parse(json); + return JSON.parse(jsonString); + }; +})(); \ No newline at end of file diff --git a/modules/system/assets/ui/js/autocomplete.js b/modules/system/assets/ui/js/autocomplete.js index 59d2b96892..331e7a8eeb 100644 --- a/modules/system/assets/ui/js/autocomplete.js +++ b/modules/system/assets/ui/js/autocomplete.js @@ -378,7 +378,7 @@ if (typeof value == 'object') return value try { - return JSON.parse(JSON.stringify(eval("({" + value + "})"))) + return octoberJSON.parse("{" + value + "}") } catch (e) { throw new Error('Error parsing the '+name+' attribute value. '+e) diff --git a/modules/system/assets/ui/js/chart.line.js b/modules/system/assets/ui/js/chart.line.js index f89b412fab..ea03d3bacb 100644 --- a/modules/system/assets/ui/js/chart.line.js +++ b/modules/system/assets/ui/js/chart.line.js @@ -80,7 +80,7 @@ var parsedOptions = {} try { - parsedOptions = JSON.parse(JSON.stringify(eval("({" + options.chartOptions + "})"))); + parsedOptions = octoberJSON.parse("{" + value + "}"); } catch (e) { throw new Error('Error parsing the data-chart-options attribute value. '+e); } diff --git a/modules/system/assets/ui/js/popup.js b/modules/system/assets/ui/js/popup.js index 2ba8f348ec..570c9bbfa7 100644 --- a/modules/system/assets/ui/js/popup.js +++ b/modules/system/assets/ui/js/popup.js @@ -395,7 +395,7 @@ if (typeof value == 'object') return value try { - return JSON.parse(JSON.stringify(eval("({" + value + "})"))) + return octoberJSON.parse("{" + value + "}") } catch (e) { throw new Error('Error parsing the '+name+' attribute value. '+e) From bf847a5a05f922582bbcaf2f65bbbfc0a796ec2d Mon Sep 17 00:00:00 2001 From: Ayumi Hamasaki <46076483+ayumihamasaki2@users.noreply.github.com> Date: Sat, 10 Aug 2019 20:53:03 +0100 Subject: [PATCH 2/9] fix my dev branch --- .../assets/js/october.relation.js | 2 +- .../widgets/form/assets/js/october.form.js | 2 +- modules/system/assets/js/framework-min.js | 2 +- .../assets/js/framework.combined-min.js | 4 +- .../system/assets/js/framework.combined.js | 1 - modules/system/assets/js/framework.extras.js | 354 ------------------ modules/system/assets/js/framework.js | 5 +- modules/system/assets/js/october.parser.js | 353 ----------------- modules/system/assets/ui/js/autocomplete.js | 2 +- modules/system/assets/ui/js/chart.line.js | 2 +- modules/system/assets/ui/js/popup.js | 2 +- 11 files changed, 9 insertions(+), 720 deletions(-) delete mode 100644 modules/system/assets/js/october.parser.js diff --git a/modules/backend/behaviors/relationcontroller/assets/js/october.relation.js b/modules/backend/behaviors/relationcontroller/assets/js/october.relation.js index b5123ed001..80bf1bea4e 100644 --- a/modules/backend/behaviors/relationcontroller/assets/js/october.relation.js +++ b/modules/backend/behaviors/relationcontroller/assets/js/october.relation.js @@ -87,7 +87,7 @@ if (typeof value == 'object') return value try { - return octoberJSON.parse("{" + value + "}") + return JSON.parse(JSON.stringify(eval("({" + value + "})"))) } catch (e) { throw new Error('Error parsing the '+name+' attribute value. '+e) diff --git a/modules/backend/widgets/form/assets/js/october.form.js b/modules/backend/widgets/form/assets/js/october.form.js index 237f12d2b5..0936d2df35 100644 --- a/modules/backend/widgets/form/assets/js/october.form.js +++ b/modules/backend/widgets/form/assets/js/october.form.js @@ -264,7 +264,7 @@ if (typeof value == 'object') return value try { - return octoberJSON.parse("{" + value + "}") + return JSON.parse(JSON.stringify(eval("({" + value + "})"))) } catch (e) { throw new Error('Error parsing the '+name+' attribute value. '+e) diff --git a/modules/system/assets/js/framework-min.js b/modules/system/assets/js/framework-min.js index d099053d3e..94fa3dc967 100644 --- a/modules/system/assets/js/framework-min.js +++ b/modules/system/assets/js/framework-min.js @@ -1,4 +1,4 @@ -"use strict";!function(){function a(e,r,n){for(var t="",o=r;o= "0" && str[pos] <= "9")) { - var body = ""; - for (var i = pos; i < str.length; i++) { - if (str[i] === "-" || str[i] === "+" || str[i] === "." || (str[i] >= "0" && str[i] <= "9")) { - body += str[i]; - } else { - return { - originLength: body.length, - body: body - }; - } - } - throw new Error("Broken JSON number body near " + body); - } - - // parse object - if (str[pos] === "{" || str[pos] === "[") { - var stack = [str[pos]]; - var body = str[pos]; - for (var i = pos + 1; i < str.length; i++) { - body += str[i]; - if (str[i] === "\\") { - if (i + 1 < str.length) body += str[i + 1]; - i++; - } else if (str[i] === "\"") { - if (stack[stack.length - 1] === "\"") { - stack.pop(); - } else if (stack[stack.length - 1] !== "'") { - stack.push(str[i]); - } - } else if (str[i] === "'") { - if (stack[stack.length - 1] === "'") { - stack.pop(); - } else if (stack[stack.length - 1] !== "\"") { - stack.push(str[i]); - } - } else if (stack[stack.length - 1] !== "\"" && stack[stack.length - 1] !== "'") { - if (str[i] === "{") { - stack.push("{"); - } else if (str[i] === "}") { - if (stack[stack.length - 1] === "{") { - stack.pop(); - } else { - throw new Error("Broken JSON " + (str[pos] === "{" ? "object" : "array") + " body near " + body); - } - } else if (str[i] === "[") { - stack.push("["); - } else if (str[i] === "]") { - if (stack[stack.length - 1] === "[") { - stack.pop(); - } else { - throw new Error("Broken JSON " + (str[pos] === "{" ? "object" : "array") + " body near " + body); - } - } - } - if (!stack.length) { - return { - originLength: i - pos, - body: body - }; - } - } - throw new Error("Broken JSON " + (str[pos] === "{" ? "object" : "array") + " body near " + body); - } - throw new Error("Broken JSON body near " + str.substr((pos - 5 >= 0) ? pos - 5 : 0, 50)); - } - - /* - * This is a char can be key head - * @param ch - * @returns {boolean} - */ - function canBeKeyHead(ch) { - if (ch[0] === "\\") return false; - if ((ch[0] >= 'a' && ch[0] <= 'z') || (ch[0] >= 'A' && ch[0] <= 'Z') || ch[0] === '_') return true; - if (ch[0] >= '0' && ch[0] <= '9') return true; - if (ch[0] === '$') return true; - if (ch.charCodeAt(0) > 255) return true; - return false; - } - - function isBlankChar(ch) { - return ch === " " || ch === "\n" || ch === "\t"; - } - - /* - * parse JSON - * @param str - */ - function parse(str) { - str = str.trim(); - if (!str.length) throw new Error("Broken JSON object."); - var result = ""; - - /* - * the mistake ',' - */ - while (str && str[0] === ",") { - str = str.substr(1); - } - - /* - * string - */ - if (str[0] === "\"" || str[0] === "'") { - if (str[str.length - 1] !== str[0]) { - throw new Error("Invalid string JSON object."); - } - - var body = "\""; - for (var i = 1; i < str.length; i++) { - if (str[i] === "\\") { - if (str[i + 1] === "'") { - body += str[i + 1] - } else { - body += str[i]; - body += str[i + 1]; - } - i++; - } else if (str[i] === str[0]) { - body += "\""; - return body - } else if (str[i] === "\"") { - body += "\\\"" - } else body += str[i]; - } - throw new Error("Invalid string JSON object."); - } - - /* - * boolean - */ - if (str === "true" || str === "false") { - return str; - } - - /* - * null - */ - if (str === "null") { - return "null"; - } - - /* - * number - */ - var num = parseFloat(str); - if (!isNaN(num)) { - return num.toString(); - } - - /* - * object - */ - if (str[0] === "{") { - var type = "needKey"; - var result = "{"; - - for (var i = 1; i < str.length; i++) { - if (isBlankChar(str[i])) { - continue; - } else if (type === "needKey" && (str[i] === "\"" || str[i] === "'")) { - var key = parseKey(str, i + 1, str[i]); - result += "\"" + key + "\""; - i += key.length; - i += 1; - type = "afterKey"; - } else if (type === "needKey" && canBeKeyHead(str[i])) { - var key = parseKey(str, i); - result += "\""; - result += key; - result += "\""; - i += key.length - 1; - type = "afterKey"; - } else if (type === "afterKey" && str[i] === ":") { - result += ":"; - type = ":"; - } else if (type === ":") { - var body = getBody(str, i); - - i = i + body.originLength - 1; - result += parse(body.body); - - type = "afterBody"; - } else if (type === "afterBody" || type === "needKey") { - var last = i; - while (str[last] === "," || isBlankChar(str[last])) { - last++; - } - if (str[last] === "}" && last === str.length - 1) { - while (result[result.length - 1] === ",") { - result = result.substr(0, result.length - 1); - } - result += "}"; - return result; - } else if (last !== i && result !== "{") { - result += ","; - type = "needKey"; - i = last - 1; - } - } - } - throw new Error("Broken JSON object near " + result); - } - - /* - * array - */ - if (str[0] === "[") { - var result = "["; - var type = "needBody"; - for (var i = 1; i < str.length; i++) { - if (" " === str[i] || "\n" === str[i] || "\t" === str[i]) { - continue; - } else if (type === "needBody") { - if (str[i] === ",") { - result += "null,"; - continue; - } - if (str[i] === "]" && i === str.length - 1) { - if (result[result.length - 1] === ",") result = result.substr(0, result.length - 1); - result += "]"; - return result; - } - - var body = getBody(str, i); - - i = i + body.originLength - 1; - result += parse(body.body); - - type = "afterBody"; - } else if (type === "afterBody") { - if (str[i] === ",") { - result += ","; - type = "needBody"; - - // deal with mistake "," - while (str[i + 1] === "," || isBlankChar(str[i + 1])) { - if (str[i + 1] === ",") result += "null,"; - i++; - } - } else if (str[i] === "]" && i === str.length - 1) { - result += "]"; - return result; - } - } - } - throw new Error("Broken JSON array near " + result); - } - } - - var g = (typeof exports === "undefined") ? (window.octoberJSON = {}) : exports; - - /* - * parse October JSON string into JSON object - * @param json - * @returns {*} - */ - g.parse = function(json) { - var jsonString = parse(json); - return JSON.parse(jsonString); - }; -})(); - +function ($) { "use strict"; if ($.oc === undefined) $.oc = {} diff --git a/modules/system/assets/js/framework.js b/modules/system/assets/js/framework.js index bfc7aaf4af..b46410183a 100644 --- a/modules/system/assets/js/framework.js +++ b/modules/system/assets/js/framework.js @@ -5,9 +5,6 @@ * Copyright 2017 Alexey Bobkov, Samuel Georges * ======================================================================== */ -/* October CMS JSON Parser */ -"use strict";!function(){function a(e,r,n){for(var t="",o=r;o= "0" && str[pos] <= "9")) { - var body = ""; - for (var i = pos; i < str.length; i++) { - if (str[i] === "-" || str[i] === "+" || str[i] === "." || (str[i] >= "0" && str[i] <= "9")) { - body += str[i]; - } else { - return { - originLength: body.length, - body: body - }; - } - } - throw new Error("Broken JSON number body near " + body); - } - - // parse object - if (str[pos] === "{" || str[pos] === "[") { - var stack = [str[pos]]; - var body = str[pos]; - for (var i = pos + 1; i < str.length; i++) { - body += str[i]; - if (str[i] === "\\") { - if (i + 1 < str.length) body += str[i + 1]; - i++; - } else if (str[i] === "\"") { - if (stack[stack.length - 1] === "\"") { - stack.pop(); - } else if (stack[stack.length - 1] !== "'") { - stack.push(str[i]); - } - } else if (str[i] === "'") { - if (stack[stack.length - 1] === "'") { - stack.pop(); - } else if (stack[stack.length - 1] !== "\"") { - stack.push(str[i]); - } - } else if (stack[stack.length - 1] !== "\"" && stack[stack.length - 1] !== "'") { - if (str[i] === "{") { - stack.push("{"); - } else if (str[i] === "}") { - if (stack[stack.length - 1] === "{") { - stack.pop(); - } else { - throw new Error("Broken JSON " + (str[pos] === "{" ? "object" : "array") + " body near " + body); - } - } else if (str[i] === "[") { - stack.push("["); - } else if (str[i] === "]") { - if (stack[stack.length - 1] === "[") { - stack.pop(); - } else { - throw new Error("Broken JSON " + (str[pos] === "{" ? "object" : "array") + " body near " + body); - } - } - } - if (!stack.length) { - return { - originLength: i - pos, - body: body - }; - } - } - throw new Error("Broken JSON " + (str[pos] === "{" ? "object" : "array") + " body near " + body); - } - throw new Error("Broken JSON body near " + str.substr((pos - 5 >= 0) ? pos - 5 : 0, 50)); - } - - /* - * This is a char can be key head - * @param ch - * @returns {boolean} - */ - function canBeKeyHead(ch) { - if (ch[0] === "\\") return false; - if ((ch[0] >= 'a' && ch[0] <= 'z') || (ch[0] >= 'A' && ch[0] <= 'Z') || ch[0] === '_') return true; - if (ch[0] >= '0' && ch[0] <= '9') return true; - if (ch[0] === '$') return true; - if (ch.charCodeAt(0) > 255) return true; - return false; - } - - function isBlankChar(ch) { - return ch === " " || ch === "\n" || ch === "\t"; - } - - /* - * parse JSON - * @param str - */ - function parse(str) { - str = str.trim(); - if (!str.length) throw new Error("Broken JSON object."); - var result = ""; - - /* - * the mistake ',' - */ - while (str && str[0] === ",") { - str = str.substr(1); - } - - /* - * string - */ - if (str[0] === "\"" || str[0] === "'") { - if (str[str.length - 1] !== str[0]) { - throw new Error("Invalid string JSON object."); - } - - var body = "\""; - for (var i = 1; i < str.length; i++) { - if (str[i] === "\\") { - if (str[i + 1] === "'") { - body += str[i + 1] - } else { - body += str[i]; - body += str[i + 1]; - } - i++; - } else if (str[i] === str[0]) { - body += "\""; - return body - } else if (str[i] === "\"") { - body += "\\\"" - } else body += str[i]; - } - throw new Error("Invalid string JSON object."); - } - - /* - * boolean - */ - if (str === "true" || str === "false") { - return str; - } - - /* - * null - */ - if (str === "null") { - return "null"; - } - - /* - * number - */ - var num = parseFloat(str); - if (!isNaN(num)) { - return num.toString(); - } - - /* - * object - */ - if (str[0] === "{") { - var type = "needKey"; - var result = "{"; - - for (var i = 1; i < str.length; i++) { - if (isBlankChar(str[i])) { - continue; - } else if (type === "needKey" && (str[i] === "\"" || str[i] === "'")) { - var key = parseKey(str, i + 1, str[i]); - result += "\"" + key + "\""; - i += key.length; - i += 1; - type = "afterKey"; - } else if (type === "needKey" && canBeKeyHead(str[i])) { - var key = parseKey(str, i); - result += "\""; - result += key; - result += "\""; - i += key.length - 1; - type = "afterKey"; - } else if (type === "afterKey" && str[i] === ":") { - result += ":"; - type = ":"; - } else if (type === ":") { - var body = getBody(str, i); - - i = i + body.originLength - 1; - result += parse(body.body); - - type = "afterBody"; - } else if (type === "afterBody" || type === "needKey") { - var last = i; - while (str[last] === "," || isBlankChar(str[last])) { - last++; - } - if (str[last] === "}" && last === str.length - 1) { - while (result[result.length - 1] === ",") { - result = result.substr(0, result.length - 1); - } - result += "}"; - return result; - } else if (last !== i && result !== "{") { - result += ","; - type = "needKey"; - i = last - 1; - } - } - } - throw new Error("Broken JSON object near " + result); - } - - /* - * array - */ - if (str[0] === "[") { - var result = "["; - var type = "needBody"; - for (var i = 1; i < str.length; i++) { - if (" " === str[i] || "\n" === str[i] || "\t" === str[i]) { - continue; - } else if (type === "needBody") { - if (str[i] === ",") { - result += "null,"; - continue; - } - if (str[i] === "]" && i === str.length - 1) { - if (result[result.length - 1] === ",") result = result.substr(0, result.length - 1); - result += "]"; - return result; - } - - var body = getBody(str, i); - - i = i + body.originLength - 1; - result += parse(body.body); - - type = "afterBody"; - } else if (type === "afterBody") { - if (str[i] === ",") { - result += ","; - type = "needBody"; - - // deal with mistake "," - while (str[i + 1] === "," || isBlankChar(str[i + 1])) { - if (str[i + 1] === ",") result += "null,"; - i++; - } - } else if (str[i] === "]" && i === str.length - 1) { - result += "]"; - return result; - } - } - } - throw new Error("Broken JSON array near " + result); - } - } - - var g = (typeof exports === "undefined") ? (window.octoberJSON = {}) : exports; - - /* - * parse October JSON string into JSON object - * @param json - * @returns {*} - */ - g.parse = function(json) { - var jsonString = parse(json); - return JSON.parse(jsonString); - }; -})(); \ No newline at end of file diff --git a/modules/system/assets/ui/js/autocomplete.js b/modules/system/assets/ui/js/autocomplete.js index 331e7a8eeb..14027c628c 100644 --- a/modules/system/assets/ui/js/autocomplete.js +++ b/modules/system/assets/ui/js/autocomplete.js @@ -378,7 +378,7 @@ if (typeof value == 'object') return value try { - return octoberJSON.parse("{" + value + "}") + return JSON.parse(JSON.stringify(eval("({" + value + "})"))) } catch (e) { throw new Error('Error parsing the '+name+' attribute value. '+e) diff --git a/modules/system/assets/ui/js/chart.line.js b/modules/system/assets/ui/js/chart.line.js index ea03d3bacb..f89b412fab 100644 --- a/modules/system/assets/ui/js/chart.line.js +++ b/modules/system/assets/ui/js/chart.line.js @@ -80,7 +80,7 @@ var parsedOptions = {} try { - parsedOptions = octoberJSON.parse("{" + value + "}"); + parsedOptions = JSON.parse(JSON.stringify(eval("({" + options.chartOptions + "})"))); } catch (e) { throw new Error('Error parsing the data-chart-options attribute value. '+e); } diff --git a/modules/system/assets/ui/js/popup.js b/modules/system/assets/ui/js/popup.js index 570c9bbfa7..2ba8f348ec 100644 --- a/modules/system/assets/ui/js/popup.js +++ b/modules/system/assets/ui/js/popup.js @@ -395,7 +395,7 @@ if (typeof value == 'object') return value try { - return octoberJSON.parse("{" + value + "}") + return JSON.parse(JSON.stringify(eval("({" + value + "})"))) } catch (e) { throw new Error('Error parsing the '+name+' attribute value. '+e) From b68b96080a1d211135732bcff4fa2afd0d7ba86f Mon Sep 17 00:00:00 2001 From: Ayumi Hamasaki <46076483+ayumihamasaki2@users.noreply.github.com> Date: Sat, 10 Aug 2019 20:54:24 +0100 Subject: [PATCH 3/9] fix dev branch 2 --- modules/system/assets/js/framework.js | 2 +- modules/system/assets/ui/js/autocomplete.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/modules/system/assets/js/framework.js b/modules/system/assets/js/framework.js index b46410183a..4330d18be3 100644 --- a/modules/system/assets/js/framework.js +++ b/modules/system/assets/js/framework.js @@ -458,7 +458,7 @@ if (window.jQuery.request !== undefined) { if (typeof value == 'object') return value try { - return JSON.parse(JSON.stringify(eval("({" + value + "})"))) + return JSON.parse(JSON.stringify(eval("({" + value + "})"))) } catch (e) { throw new Error('Error parsing the '+name+' attribute value. '+e) diff --git a/modules/system/assets/ui/js/autocomplete.js b/modules/system/assets/ui/js/autocomplete.js index 14027c628c..59d2b96892 100644 --- a/modules/system/assets/ui/js/autocomplete.js +++ b/modules/system/assets/ui/js/autocomplete.js @@ -378,7 +378,7 @@ if (typeof value == 'object') return value try { - return JSON.parse(JSON.stringify(eval("({" + value + "})"))) + return JSON.parse(JSON.stringify(eval("({" + value + "})"))) } catch (e) { throw new Error('Error parsing the '+name+' attribute value. '+e) From 577aa3b882de1e5e88858043007cd7aaa294ee0e Mon Sep 17 00:00:00 2001 From: Ayumi Hamasaki <46076483+ayumihamasaki2@users.noreply.github.com> Date: Sat, 10 Aug 2019 21:02:06 +0100 Subject: [PATCH 4/9] Revert "fix dev branch 2" This reverts commit b68b96080a1d211135732bcff4fa2afd0d7ba86f. --- modules/system/assets/js/framework.js | 2 +- modules/system/assets/ui/js/autocomplete.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/modules/system/assets/js/framework.js b/modules/system/assets/js/framework.js index 4330d18be3..b46410183a 100644 --- a/modules/system/assets/js/framework.js +++ b/modules/system/assets/js/framework.js @@ -458,7 +458,7 @@ if (window.jQuery.request !== undefined) { if (typeof value == 'object') return value try { - return JSON.parse(JSON.stringify(eval("({" + value + "})"))) + return JSON.parse(JSON.stringify(eval("({" + value + "})"))) } catch (e) { throw new Error('Error parsing the '+name+' attribute value. '+e) diff --git a/modules/system/assets/ui/js/autocomplete.js b/modules/system/assets/ui/js/autocomplete.js index 59d2b96892..14027c628c 100644 --- a/modules/system/assets/ui/js/autocomplete.js +++ b/modules/system/assets/ui/js/autocomplete.js @@ -378,7 +378,7 @@ if (typeof value == 'object') return value try { - return JSON.parse(JSON.stringify(eval("({" + value + "})"))) + return JSON.parse(JSON.stringify(eval("({" + value + "})"))) } catch (e) { throw new Error('Error parsing the '+name+' attribute value. '+e) From b2ae858cd5d1147f15da70ac2ec1dba1f658a46b Mon Sep 17 00:00:00 2001 From: Ayumi Hamasaki <46076483+ayumihamasaki2@users.noreply.github.com> Date: Sat, 10 Aug 2019 21:02:12 +0100 Subject: [PATCH 5/9] Revert "fix my dev branch" This reverts commit bf847a5a05f922582bbcaf2f65bbbfc0a796ec2d. --- .../assets/js/october.relation.js | 2 +- .../widgets/form/assets/js/october.form.js | 2 +- modules/system/assets/js/framework-min.js | 2 +- .../assets/js/framework.combined-min.js | 4 +- .../system/assets/js/framework.combined.js | 1 + modules/system/assets/js/framework.extras.js | 354 ++++++++++++++++++ modules/system/assets/js/framework.js | 5 +- modules/system/assets/js/october.parser.js | 353 +++++++++++++++++ modules/system/assets/ui/js/autocomplete.js | 2 +- modules/system/assets/ui/js/chart.line.js | 2 +- modules/system/assets/ui/js/popup.js | 2 +- 11 files changed, 720 insertions(+), 9 deletions(-) create mode 100644 modules/system/assets/js/october.parser.js diff --git a/modules/backend/behaviors/relationcontroller/assets/js/october.relation.js b/modules/backend/behaviors/relationcontroller/assets/js/october.relation.js index 80bf1bea4e..b5123ed001 100644 --- a/modules/backend/behaviors/relationcontroller/assets/js/october.relation.js +++ b/modules/backend/behaviors/relationcontroller/assets/js/october.relation.js @@ -87,7 +87,7 @@ if (typeof value == 'object') return value try { - return JSON.parse(JSON.stringify(eval("({" + value + "})"))) + return octoberJSON.parse("{" + value + "}") } catch (e) { throw new Error('Error parsing the '+name+' attribute value. '+e) diff --git a/modules/backend/widgets/form/assets/js/october.form.js b/modules/backend/widgets/form/assets/js/october.form.js index 0936d2df35..237f12d2b5 100644 --- a/modules/backend/widgets/form/assets/js/october.form.js +++ b/modules/backend/widgets/form/assets/js/october.form.js @@ -264,7 +264,7 @@ if (typeof value == 'object') return value try { - return JSON.parse(JSON.stringify(eval("({" + value + "})"))) + return octoberJSON.parse("{" + value + "}") } catch (e) { throw new Error('Error parsing the '+name+' attribute value. '+e) diff --git a/modules/system/assets/js/framework-min.js b/modules/system/assets/js/framework-min.js index 94fa3dc967..d099053d3e 100644 --- a/modules/system/assets/js/framework-min.js +++ b/modules/system/assets/js/framework-min.js @@ -1,4 +1,4 @@ - +"use strict";!function(){function a(e,r,n){for(var t="",o=r;o= "0" && str[pos] <= "9")) { + var body = ""; + for (var i = pos; i < str.length; i++) { + if (str[i] === "-" || str[i] === "+" || str[i] === "." || (str[i] >= "0" && str[i] <= "9")) { + body += str[i]; + } else { + return { + originLength: body.length, + body: body + }; + } + } + throw new Error("Broken JSON number body near " + body); + } + + // parse object + if (str[pos] === "{" || str[pos] === "[") { + var stack = [str[pos]]; + var body = str[pos]; + for (var i = pos + 1; i < str.length; i++) { + body += str[i]; + if (str[i] === "\\") { + if (i + 1 < str.length) body += str[i + 1]; + i++; + } else if (str[i] === "\"") { + if (stack[stack.length - 1] === "\"") { + stack.pop(); + } else if (stack[stack.length - 1] !== "'") { + stack.push(str[i]); + } + } else if (str[i] === "'") { + if (stack[stack.length - 1] === "'") { + stack.pop(); + } else if (stack[stack.length - 1] !== "\"") { + stack.push(str[i]); + } + } else if (stack[stack.length - 1] !== "\"" && stack[stack.length - 1] !== "'") { + if (str[i] === "{") { + stack.push("{"); + } else if (str[i] === "}") { + if (stack[stack.length - 1] === "{") { + stack.pop(); + } else { + throw new Error("Broken JSON " + (str[pos] === "{" ? "object" : "array") + " body near " + body); + } + } else if (str[i] === "[") { + stack.push("["); + } else if (str[i] === "]") { + if (stack[stack.length - 1] === "[") { + stack.pop(); + } else { + throw new Error("Broken JSON " + (str[pos] === "{" ? "object" : "array") + " body near " + body); + } + } + } + if (!stack.length) { + return { + originLength: i - pos, + body: body + }; + } + } + throw new Error("Broken JSON " + (str[pos] === "{" ? "object" : "array") + " body near " + body); + } + throw new Error("Broken JSON body near " + str.substr((pos - 5 >= 0) ? pos - 5 : 0, 50)); + } + + /* + * This is a char can be key head + * @param ch + * @returns {boolean} + */ + function canBeKeyHead(ch) { + if (ch[0] === "\\") return false; + if ((ch[0] >= 'a' && ch[0] <= 'z') || (ch[0] >= 'A' && ch[0] <= 'Z') || ch[0] === '_') return true; + if (ch[0] >= '0' && ch[0] <= '9') return true; + if (ch[0] === '$') return true; + if (ch.charCodeAt(0) > 255) return true; + return false; + } + + function isBlankChar(ch) { + return ch === " " || ch === "\n" || ch === "\t"; + } + + /* + * parse JSON + * @param str + */ + function parse(str) { + str = str.trim(); + if (!str.length) throw new Error("Broken JSON object."); + var result = ""; + + /* + * the mistake ',' + */ + while (str && str[0] === ",") { + str = str.substr(1); + } + + /* + * string + */ + if (str[0] === "\"" || str[0] === "'") { + if (str[str.length - 1] !== str[0]) { + throw new Error("Invalid string JSON object."); + } + + var body = "\""; + for (var i = 1; i < str.length; i++) { + if (str[i] === "\\") { + if (str[i + 1] === "'") { + body += str[i + 1] + } else { + body += str[i]; + body += str[i + 1]; + } + i++; + } else if (str[i] === str[0]) { + body += "\""; + return body + } else if (str[i] === "\"") { + body += "\\\"" + } else body += str[i]; + } + throw new Error("Invalid string JSON object."); + } + + /* + * boolean + */ + if (str === "true" || str === "false") { + return str; + } + + /* + * null + */ + if (str === "null") { + return "null"; + } + + /* + * number + */ + var num = parseFloat(str); + if (!isNaN(num)) { + return num.toString(); + } + + /* + * object + */ + if (str[0] === "{") { + var type = "needKey"; + var result = "{"; + + for (var i = 1; i < str.length; i++) { + if (isBlankChar(str[i])) { + continue; + } else if (type === "needKey" && (str[i] === "\"" || str[i] === "'")) { + var key = parseKey(str, i + 1, str[i]); + result += "\"" + key + "\""; + i += key.length; + i += 1; + type = "afterKey"; + } else if (type === "needKey" && canBeKeyHead(str[i])) { + var key = parseKey(str, i); + result += "\""; + result += key; + result += "\""; + i += key.length - 1; + type = "afterKey"; + } else if (type === "afterKey" && str[i] === ":") { + result += ":"; + type = ":"; + } else if (type === ":") { + var body = getBody(str, i); + + i = i + body.originLength - 1; + result += parse(body.body); + + type = "afterBody"; + } else if (type === "afterBody" || type === "needKey") { + var last = i; + while (str[last] === "," || isBlankChar(str[last])) { + last++; + } + if (str[last] === "}" && last === str.length - 1) { + while (result[result.length - 1] === ",") { + result = result.substr(0, result.length - 1); + } + result += "}"; + return result; + } else if (last !== i && result !== "{") { + result += ","; + type = "needKey"; + i = last - 1; + } + } + } + throw new Error("Broken JSON object near " + result); + } + + /* + * array + */ + if (str[0] === "[") { + var result = "["; + var type = "needBody"; + for (var i = 1; i < str.length; i++) { + if (" " === str[i] || "\n" === str[i] || "\t" === str[i]) { + continue; + } else if (type === "needBody") { + if (str[i] === ",") { + result += "null,"; + continue; + } + if (str[i] === "]" && i === str.length - 1) { + if (result[result.length - 1] === ",") result = result.substr(0, result.length - 1); + result += "]"; + return result; + } + + var body = getBody(str, i); + + i = i + body.originLength - 1; + result += parse(body.body); + + type = "afterBody"; + } else if (type === "afterBody") { + if (str[i] === ",") { + result += ","; + type = "needBody"; + + // deal with mistake "," + while (str[i + 1] === "," || isBlankChar(str[i + 1])) { + if (str[i + 1] === ",") result += "null,"; + i++; + } + } else if (str[i] === "]" && i === str.length - 1) { + result += "]"; + return result; + } + } + } + throw new Error("Broken JSON array near " + result); + } + } + + var g = (typeof exports === "undefined") ? (window.octoberJSON = {}) : exports; + + /* + * parse October JSON string into JSON object + * @param json + * @returns {*} + */ + g.parse = function(json) { + var jsonString = parse(json); + return JSON.parse(jsonString); + }; +})(); + +function ($) { "use strict"; if ($.oc === undefined) $.oc = {} diff --git a/modules/system/assets/js/framework.js b/modules/system/assets/js/framework.js index b46410183a..bfc7aaf4af 100644 --- a/modules/system/assets/js/framework.js +++ b/modules/system/assets/js/framework.js @@ -5,6 +5,9 @@ * Copyright 2017 Alexey Bobkov, Samuel Georges * ======================================================================== */ +/* October CMS JSON Parser */ +"use strict";!function(){function a(e,r,n){for(var t="",o=r;o= "0" && str[pos] <= "9")) { + var body = ""; + for (var i = pos; i < str.length; i++) { + if (str[i] === "-" || str[i] === "+" || str[i] === "." || (str[i] >= "0" && str[i] <= "9")) { + body += str[i]; + } else { + return { + originLength: body.length, + body: body + }; + } + } + throw new Error("Broken JSON number body near " + body); + } + + // parse object + if (str[pos] === "{" || str[pos] === "[") { + var stack = [str[pos]]; + var body = str[pos]; + for (var i = pos + 1; i < str.length; i++) { + body += str[i]; + if (str[i] === "\\") { + if (i + 1 < str.length) body += str[i + 1]; + i++; + } else if (str[i] === "\"") { + if (stack[stack.length - 1] === "\"") { + stack.pop(); + } else if (stack[stack.length - 1] !== "'") { + stack.push(str[i]); + } + } else if (str[i] === "'") { + if (stack[stack.length - 1] === "'") { + stack.pop(); + } else if (stack[stack.length - 1] !== "\"") { + stack.push(str[i]); + } + } else if (stack[stack.length - 1] !== "\"" && stack[stack.length - 1] !== "'") { + if (str[i] === "{") { + stack.push("{"); + } else if (str[i] === "}") { + if (stack[stack.length - 1] === "{") { + stack.pop(); + } else { + throw new Error("Broken JSON " + (str[pos] === "{" ? "object" : "array") + " body near " + body); + } + } else if (str[i] === "[") { + stack.push("["); + } else if (str[i] === "]") { + if (stack[stack.length - 1] === "[") { + stack.pop(); + } else { + throw new Error("Broken JSON " + (str[pos] === "{" ? "object" : "array") + " body near " + body); + } + } + } + if (!stack.length) { + return { + originLength: i - pos, + body: body + }; + } + } + throw new Error("Broken JSON " + (str[pos] === "{" ? "object" : "array") + " body near " + body); + } + throw new Error("Broken JSON body near " + str.substr((pos - 5 >= 0) ? pos - 5 : 0, 50)); + } + + /* + * This is a char can be key head + * @param ch + * @returns {boolean} + */ + function canBeKeyHead(ch) { + if (ch[0] === "\\") return false; + if ((ch[0] >= 'a' && ch[0] <= 'z') || (ch[0] >= 'A' && ch[0] <= 'Z') || ch[0] === '_') return true; + if (ch[0] >= '0' && ch[0] <= '9') return true; + if (ch[0] === '$') return true; + if (ch.charCodeAt(0) > 255) return true; + return false; + } + + function isBlankChar(ch) { + return ch === " " || ch === "\n" || ch === "\t"; + } + + /* + * parse JSON + * @param str + */ + function parse(str) { + str = str.trim(); + if (!str.length) throw new Error("Broken JSON object."); + var result = ""; + + /* + * the mistake ',' + */ + while (str && str[0] === ",") { + str = str.substr(1); + } + + /* + * string + */ + if (str[0] === "\"" || str[0] === "'") { + if (str[str.length - 1] !== str[0]) { + throw new Error("Invalid string JSON object."); + } + + var body = "\""; + for (var i = 1; i < str.length; i++) { + if (str[i] === "\\") { + if (str[i + 1] === "'") { + body += str[i + 1] + } else { + body += str[i]; + body += str[i + 1]; + } + i++; + } else if (str[i] === str[0]) { + body += "\""; + return body + } else if (str[i] === "\"") { + body += "\\\"" + } else body += str[i]; + } + throw new Error("Invalid string JSON object."); + } + + /* + * boolean + */ + if (str === "true" || str === "false") { + return str; + } + + /* + * null + */ + if (str === "null") { + return "null"; + } + + /* + * number + */ + var num = parseFloat(str); + if (!isNaN(num)) { + return num.toString(); + } + + /* + * object + */ + if (str[0] === "{") { + var type = "needKey"; + var result = "{"; + + for (var i = 1; i < str.length; i++) { + if (isBlankChar(str[i])) { + continue; + } else if (type === "needKey" && (str[i] === "\"" || str[i] === "'")) { + var key = parseKey(str, i + 1, str[i]); + result += "\"" + key + "\""; + i += key.length; + i += 1; + type = "afterKey"; + } else if (type === "needKey" && canBeKeyHead(str[i])) { + var key = parseKey(str, i); + result += "\""; + result += key; + result += "\""; + i += key.length - 1; + type = "afterKey"; + } else if (type === "afterKey" && str[i] === ":") { + result += ":"; + type = ":"; + } else if (type === ":") { + var body = getBody(str, i); + + i = i + body.originLength - 1; + result += parse(body.body); + + type = "afterBody"; + } else if (type === "afterBody" || type === "needKey") { + var last = i; + while (str[last] === "," || isBlankChar(str[last])) { + last++; + } + if (str[last] === "}" && last === str.length - 1) { + while (result[result.length - 1] === ",") { + result = result.substr(0, result.length - 1); + } + result += "}"; + return result; + } else if (last !== i && result !== "{") { + result += ","; + type = "needKey"; + i = last - 1; + } + } + } + throw new Error("Broken JSON object near " + result); + } + + /* + * array + */ + if (str[0] === "[") { + var result = "["; + var type = "needBody"; + for (var i = 1; i < str.length; i++) { + if (" " === str[i] || "\n" === str[i] || "\t" === str[i]) { + continue; + } else if (type === "needBody") { + if (str[i] === ",") { + result += "null,"; + continue; + } + if (str[i] === "]" && i === str.length - 1) { + if (result[result.length - 1] === ",") result = result.substr(0, result.length - 1); + result += "]"; + return result; + } + + var body = getBody(str, i); + + i = i + body.originLength - 1; + result += parse(body.body); + + type = "afterBody"; + } else if (type === "afterBody") { + if (str[i] === ",") { + result += ","; + type = "needBody"; + + // deal with mistake "," + while (str[i + 1] === "," || isBlankChar(str[i + 1])) { + if (str[i + 1] === ",") result += "null,"; + i++; + } + } else if (str[i] === "]" && i === str.length - 1) { + result += "]"; + return result; + } + } + } + throw new Error("Broken JSON array near " + result); + } + } + + var g = (typeof exports === "undefined") ? (window.octoberJSON = {}) : exports; + + /* + * parse October JSON string into JSON object + * @param json + * @returns {*} + */ + g.parse = function(json) { + var jsonString = parse(json); + return JSON.parse(jsonString); + }; +})(); \ No newline at end of file diff --git a/modules/system/assets/ui/js/autocomplete.js b/modules/system/assets/ui/js/autocomplete.js index 14027c628c..331e7a8eeb 100644 --- a/modules/system/assets/ui/js/autocomplete.js +++ b/modules/system/assets/ui/js/autocomplete.js @@ -378,7 +378,7 @@ if (typeof value == 'object') return value try { - return JSON.parse(JSON.stringify(eval("({" + value + "})"))) + return octoberJSON.parse("{" + value + "}") } catch (e) { throw new Error('Error parsing the '+name+' attribute value. '+e) diff --git a/modules/system/assets/ui/js/chart.line.js b/modules/system/assets/ui/js/chart.line.js index f89b412fab..ea03d3bacb 100644 --- a/modules/system/assets/ui/js/chart.line.js +++ b/modules/system/assets/ui/js/chart.line.js @@ -80,7 +80,7 @@ var parsedOptions = {} try { - parsedOptions = JSON.parse(JSON.stringify(eval("({" + options.chartOptions + "})"))); + parsedOptions = octoberJSON.parse("{" + value + "}"); } catch (e) { throw new Error('Error parsing the data-chart-options attribute value. '+e); } diff --git a/modules/system/assets/ui/js/popup.js b/modules/system/assets/ui/js/popup.js index 2ba8f348ec..570c9bbfa7 100644 --- a/modules/system/assets/ui/js/popup.js +++ b/modules/system/assets/ui/js/popup.js @@ -395,7 +395,7 @@ if (typeof value == 'object') return value try { - return JSON.parse(JSON.stringify(eval("({" + value + "})"))) + return octoberJSON.parse("{" + value + "}") } catch (e) { throw new Error('Error parsing the '+name+' attribute value. '+e) From 86a0b49d947b2e8049aaafe8745e4e0215198374 Mon Sep 17 00:00:00 2001 From: Ayumi Hamasaki <46076483+ayumihamasaki2@users.noreply.github.com> Date: Sat, 10 Aug 2019 21:02:17 +0100 Subject: [PATCH 6/9] Revert "Add a small JSON Parser to October framework lib" This reverts commit 46bba7dc03a87e51c8029366234b2044b359b311. --- .../assets/js/october.relation.js | 2 +- .../widgets/form/assets/js/october.form.js | 2 +- modules/system/assets/js/framework-min.js | 2 +- .../assets/js/framework.combined-min.js | 4 +- .../system/assets/js/framework.combined.js | 1 - modules/system/assets/js/framework.extras.js | 354 ------------------ modules/system/assets/js/framework.js | 5 +- modules/system/assets/js/october.parser.js | 353 ----------------- modules/system/assets/ui/js/autocomplete.js | 2 +- modules/system/assets/ui/js/chart.line.js | 2 +- modules/system/assets/ui/js/popup.js | 2 +- 11 files changed, 9 insertions(+), 720 deletions(-) delete mode 100644 modules/system/assets/js/october.parser.js diff --git a/modules/backend/behaviors/relationcontroller/assets/js/october.relation.js b/modules/backend/behaviors/relationcontroller/assets/js/october.relation.js index b5123ed001..80bf1bea4e 100644 --- a/modules/backend/behaviors/relationcontroller/assets/js/october.relation.js +++ b/modules/backend/behaviors/relationcontroller/assets/js/october.relation.js @@ -87,7 +87,7 @@ if (typeof value == 'object') return value try { - return octoberJSON.parse("{" + value + "}") + return JSON.parse(JSON.stringify(eval("({" + value + "})"))) } catch (e) { throw new Error('Error parsing the '+name+' attribute value. '+e) diff --git a/modules/backend/widgets/form/assets/js/october.form.js b/modules/backend/widgets/form/assets/js/october.form.js index 237f12d2b5..0936d2df35 100644 --- a/modules/backend/widgets/form/assets/js/october.form.js +++ b/modules/backend/widgets/form/assets/js/october.form.js @@ -264,7 +264,7 @@ if (typeof value == 'object') return value try { - return octoberJSON.parse("{" + value + "}") + return JSON.parse(JSON.stringify(eval("({" + value + "})"))) } catch (e) { throw new Error('Error parsing the '+name+' attribute value. '+e) diff --git a/modules/system/assets/js/framework-min.js b/modules/system/assets/js/framework-min.js index d099053d3e..94fa3dc967 100644 --- a/modules/system/assets/js/framework-min.js +++ b/modules/system/assets/js/framework-min.js @@ -1,4 +1,4 @@ -"use strict";!function(){function a(e,r,n){for(var t="",o=r;o= "0" && str[pos] <= "9")) { - var body = ""; - for (var i = pos; i < str.length; i++) { - if (str[i] === "-" || str[i] === "+" || str[i] === "." || (str[i] >= "0" && str[i] <= "9")) { - body += str[i]; - } else { - return { - originLength: body.length, - body: body - }; - } - } - throw new Error("Broken JSON number body near " + body); - } - - // parse object - if (str[pos] === "{" || str[pos] === "[") { - var stack = [str[pos]]; - var body = str[pos]; - for (var i = pos + 1; i < str.length; i++) { - body += str[i]; - if (str[i] === "\\") { - if (i + 1 < str.length) body += str[i + 1]; - i++; - } else if (str[i] === "\"") { - if (stack[stack.length - 1] === "\"") { - stack.pop(); - } else if (stack[stack.length - 1] !== "'") { - stack.push(str[i]); - } - } else if (str[i] === "'") { - if (stack[stack.length - 1] === "'") { - stack.pop(); - } else if (stack[stack.length - 1] !== "\"") { - stack.push(str[i]); - } - } else if (stack[stack.length - 1] !== "\"" && stack[stack.length - 1] !== "'") { - if (str[i] === "{") { - stack.push("{"); - } else if (str[i] === "}") { - if (stack[stack.length - 1] === "{") { - stack.pop(); - } else { - throw new Error("Broken JSON " + (str[pos] === "{" ? "object" : "array") + " body near " + body); - } - } else if (str[i] === "[") { - stack.push("["); - } else if (str[i] === "]") { - if (stack[stack.length - 1] === "[") { - stack.pop(); - } else { - throw new Error("Broken JSON " + (str[pos] === "{" ? "object" : "array") + " body near " + body); - } - } - } - if (!stack.length) { - return { - originLength: i - pos, - body: body - }; - } - } - throw new Error("Broken JSON " + (str[pos] === "{" ? "object" : "array") + " body near " + body); - } - throw new Error("Broken JSON body near " + str.substr((pos - 5 >= 0) ? pos - 5 : 0, 50)); - } - - /* - * This is a char can be key head - * @param ch - * @returns {boolean} - */ - function canBeKeyHead(ch) { - if (ch[0] === "\\") return false; - if ((ch[0] >= 'a' && ch[0] <= 'z') || (ch[0] >= 'A' && ch[0] <= 'Z') || ch[0] === '_') return true; - if (ch[0] >= '0' && ch[0] <= '9') return true; - if (ch[0] === '$') return true; - if (ch.charCodeAt(0) > 255) return true; - return false; - } - - function isBlankChar(ch) { - return ch === " " || ch === "\n" || ch === "\t"; - } - - /* - * parse JSON - * @param str - */ - function parse(str) { - str = str.trim(); - if (!str.length) throw new Error("Broken JSON object."); - var result = ""; - - /* - * the mistake ',' - */ - while (str && str[0] === ",") { - str = str.substr(1); - } - - /* - * string - */ - if (str[0] === "\"" || str[0] === "'") { - if (str[str.length - 1] !== str[0]) { - throw new Error("Invalid string JSON object."); - } - - var body = "\""; - for (var i = 1; i < str.length; i++) { - if (str[i] === "\\") { - if (str[i + 1] === "'") { - body += str[i + 1] - } else { - body += str[i]; - body += str[i + 1]; - } - i++; - } else if (str[i] === str[0]) { - body += "\""; - return body - } else if (str[i] === "\"") { - body += "\\\"" - } else body += str[i]; - } - throw new Error("Invalid string JSON object."); - } - - /* - * boolean - */ - if (str === "true" || str === "false") { - return str; - } - - /* - * null - */ - if (str === "null") { - return "null"; - } - - /* - * number - */ - var num = parseFloat(str); - if (!isNaN(num)) { - return num.toString(); - } - - /* - * object - */ - if (str[0] === "{") { - var type = "needKey"; - var result = "{"; - - for (var i = 1; i < str.length; i++) { - if (isBlankChar(str[i])) { - continue; - } else if (type === "needKey" && (str[i] === "\"" || str[i] === "'")) { - var key = parseKey(str, i + 1, str[i]); - result += "\"" + key + "\""; - i += key.length; - i += 1; - type = "afterKey"; - } else if (type === "needKey" && canBeKeyHead(str[i])) { - var key = parseKey(str, i); - result += "\""; - result += key; - result += "\""; - i += key.length - 1; - type = "afterKey"; - } else if (type === "afterKey" && str[i] === ":") { - result += ":"; - type = ":"; - } else if (type === ":") { - var body = getBody(str, i); - - i = i + body.originLength - 1; - result += parse(body.body); - - type = "afterBody"; - } else if (type === "afterBody" || type === "needKey") { - var last = i; - while (str[last] === "," || isBlankChar(str[last])) { - last++; - } - if (str[last] === "}" && last === str.length - 1) { - while (result[result.length - 1] === ",") { - result = result.substr(0, result.length - 1); - } - result += "}"; - return result; - } else if (last !== i && result !== "{") { - result += ","; - type = "needKey"; - i = last - 1; - } - } - } - throw new Error("Broken JSON object near " + result); - } - - /* - * array - */ - if (str[0] === "[") { - var result = "["; - var type = "needBody"; - for (var i = 1; i < str.length; i++) { - if (" " === str[i] || "\n" === str[i] || "\t" === str[i]) { - continue; - } else if (type === "needBody") { - if (str[i] === ",") { - result += "null,"; - continue; - } - if (str[i] === "]" && i === str.length - 1) { - if (result[result.length - 1] === ",") result = result.substr(0, result.length - 1); - result += "]"; - return result; - } - - var body = getBody(str, i); - - i = i + body.originLength - 1; - result += parse(body.body); - - type = "afterBody"; - } else if (type === "afterBody") { - if (str[i] === ",") { - result += ","; - type = "needBody"; - - // deal with mistake "," - while (str[i + 1] === "," || isBlankChar(str[i + 1])) { - if (str[i + 1] === ",") result += "null,"; - i++; - } - } else if (str[i] === "]" && i === str.length - 1) { - result += "]"; - return result; - } - } - } - throw new Error("Broken JSON array near " + result); - } - } - - var g = (typeof exports === "undefined") ? (window.octoberJSON = {}) : exports; - - /* - * parse October JSON string into JSON object - * @param json - * @returns {*} - */ - g.parse = function(json) { - var jsonString = parse(json); - return JSON.parse(jsonString); - }; -})(); - +function ($) { "use strict"; if ($.oc === undefined) $.oc = {} diff --git a/modules/system/assets/js/framework.js b/modules/system/assets/js/framework.js index bfc7aaf4af..4330d18be3 100644 --- a/modules/system/assets/js/framework.js +++ b/modules/system/assets/js/framework.js @@ -5,9 +5,6 @@ * Copyright 2017 Alexey Bobkov, Samuel Georges * ======================================================================== */ -/* October CMS JSON Parser */ -"use strict";!function(){function a(e,r,n){for(var t="",o=r;o= "0" && str[pos] <= "9")) { - var body = ""; - for (var i = pos; i < str.length; i++) { - if (str[i] === "-" || str[i] === "+" || str[i] === "." || (str[i] >= "0" && str[i] <= "9")) { - body += str[i]; - } else { - return { - originLength: body.length, - body: body - }; - } - } - throw new Error("Broken JSON number body near " + body); - } - - // parse object - if (str[pos] === "{" || str[pos] === "[") { - var stack = [str[pos]]; - var body = str[pos]; - for (var i = pos + 1; i < str.length; i++) { - body += str[i]; - if (str[i] === "\\") { - if (i + 1 < str.length) body += str[i + 1]; - i++; - } else if (str[i] === "\"") { - if (stack[stack.length - 1] === "\"") { - stack.pop(); - } else if (stack[stack.length - 1] !== "'") { - stack.push(str[i]); - } - } else if (str[i] === "'") { - if (stack[stack.length - 1] === "'") { - stack.pop(); - } else if (stack[stack.length - 1] !== "\"") { - stack.push(str[i]); - } - } else if (stack[stack.length - 1] !== "\"" && stack[stack.length - 1] !== "'") { - if (str[i] === "{") { - stack.push("{"); - } else if (str[i] === "}") { - if (stack[stack.length - 1] === "{") { - stack.pop(); - } else { - throw new Error("Broken JSON " + (str[pos] === "{" ? "object" : "array") + " body near " + body); - } - } else if (str[i] === "[") { - stack.push("["); - } else if (str[i] === "]") { - if (stack[stack.length - 1] === "[") { - stack.pop(); - } else { - throw new Error("Broken JSON " + (str[pos] === "{" ? "object" : "array") + " body near " + body); - } - } - } - if (!stack.length) { - return { - originLength: i - pos, - body: body - }; - } - } - throw new Error("Broken JSON " + (str[pos] === "{" ? "object" : "array") + " body near " + body); - } - throw new Error("Broken JSON body near " + str.substr((pos - 5 >= 0) ? pos - 5 : 0, 50)); - } - - /* - * This is a char can be key head - * @param ch - * @returns {boolean} - */ - function canBeKeyHead(ch) { - if (ch[0] === "\\") return false; - if ((ch[0] >= 'a' && ch[0] <= 'z') || (ch[0] >= 'A' && ch[0] <= 'Z') || ch[0] === '_') return true; - if (ch[0] >= '0' && ch[0] <= '9') return true; - if (ch[0] === '$') return true; - if (ch.charCodeAt(0) > 255) return true; - return false; - } - - function isBlankChar(ch) { - return ch === " " || ch === "\n" || ch === "\t"; - } - - /* - * parse JSON - * @param str - */ - function parse(str) { - str = str.trim(); - if (!str.length) throw new Error("Broken JSON object."); - var result = ""; - - /* - * the mistake ',' - */ - while (str && str[0] === ",") { - str = str.substr(1); - } - - /* - * string - */ - if (str[0] === "\"" || str[0] === "'") { - if (str[str.length - 1] !== str[0]) { - throw new Error("Invalid string JSON object."); - } - - var body = "\""; - for (var i = 1; i < str.length; i++) { - if (str[i] === "\\") { - if (str[i + 1] === "'") { - body += str[i + 1] - } else { - body += str[i]; - body += str[i + 1]; - } - i++; - } else if (str[i] === str[0]) { - body += "\""; - return body - } else if (str[i] === "\"") { - body += "\\\"" - } else body += str[i]; - } - throw new Error("Invalid string JSON object."); - } - - /* - * boolean - */ - if (str === "true" || str === "false") { - return str; - } - - /* - * null - */ - if (str === "null") { - return "null"; - } - - /* - * number - */ - var num = parseFloat(str); - if (!isNaN(num)) { - return num.toString(); - } - - /* - * object - */ - if (str[0] === "{") { - var type = "needKey"; - var result = "{"; - - for (var i = 1; i < str.length; i++) { - if (isBlankChar(str[i])) { - continue; - } else if (type === "needKey" && (str[i] === "\"" || str[i] === "'")) { - var key = parseKey(str, i + 1, str[i]); - result += "\"" + key + "\""; - i += key.length; - i += 1; - type = "afterKey"; - } else if (type === "needKey" && canBeKeyHead(str[i])) { - var key = parseKey(str, i); - result += "\""; - result += key; - result += "\""; - i += key.length - 1; - type = "afterKey"; - } else if (type === "afterKey" && str[i] === ":") { - result += ":"; - type = ":"; - } else if (type === ":") { - var body = getBody(str, i); - - i = i + body.originLength - 1; - result += parse(body.body); - - type = "afterBody"; - } else if (type === "afterBody" || type === "needKey") { - var last = i; - while (str[last] === "," || isBlankChar(str[last])) { - last++; - } - if (str[last] === "}" && last === str.length - 1) { - while (result[result.length - 1] === ",") { - result = result.substr(0, result.length - 1); - } - result += "}"; - return result; - } else if (last !== i && result !== "{") { - result += ","; - type = "needKey"; - i = last - 1; - } - } - } - throw new Error("Broken JSON object near " + result); - } - - /* - * array - */ - if (str[0] === "[") { - var result = "["; - var type = "needBody"; - for (var i = 1; i < str.length; i++) { - if (" " === str[i] || "\n" === str[i] || "\t" === str[i]) { - continue; - } else if (type === "needBody") { - if (str[i] === ",") { - result += "null,"; - continue; - } - if (str[i] === "]" && i === str.length - 1) { - if (result[result.length - 1] === ",") result = result.substr(0, result.length - 1); - result += "]"; - return result; - } - - var body = getBody(str, i); - - i = i + body.originLength - 1; - result += parse(body.body); - - type = "afterBody"; - } else if (type === "afterBody") { - if (str[i] === ",") { - result += ","; - type = "needBody"; - - // deal with mistake "," - while (str[i + 1] === "," || isBlankChar(str[i + 1])) { - if (str[i + 1] === ",") result += "null,"; - i++; - } - } else if (str[i] === "]" && i === str.length - 1) { - result += "]"; - return result; - } - } - } - throw new Error("Broken JSON array near " + result); - } - } - - var g = (typeof exports === "undefined") ? (window.octoberJSON = {}) : exports; - - /* - * parse October JSON string into JSON object - * @param json - * @returns {*} - */ - g.parse = function(json) { - var jsonString = parse(json); - return JSON.parse(jsonString); - }; -})(); \ No newline at end of file diff --git a/modules/system/assets/ui/js/autocomplete.js b/modules/system/assets/ui/js/autocomplete.js index 331e7a8eeb..59d2b96892 100644 --- a/modules/system/assets/ui/js/autocomplete.js +++ b/modules/system/assets/ui/js/autocomplete.js @@ -378,7 +378,7 @@ if (typeof value == 'object') return value try { - return octoberJSON.parse("{" + value + "}") + return JSON.parse(JSON.stringify(eval("({" + value + "})"))) } catch (e) { throw new Error('Error parsing the '+name+' attribute value. '+e) diff --git a/modules/system/assets/ui/js/chart.line.js b/modules/system/assets/ui/js/chart.line.js index ea03d3bacb..f89b412fab 100644 --- a/modules/system/assets/ui/js/chart.line.js +++ b/modules/system/assets/ui/js/chart.line.js @@ -80,7 +80,7 @@ var parsedOptions = {} try { - parsedOptions = octoberJSON.parse("{" + value + "}"); + parsedOptions = JSON.parse(JSON.stringify(eval("({" + options.chartOptions + "})"))); } catch (e) { throw new Error('Error parsing the data-chart-options attribute value. '+e); } diff --git a/modules/system/assets/ui/js/popup.js b/modules/system/assets/ui/js/popup.js index 570c9bbfa7..2ba8f348ec 100644 --- a/modules/system/assets/ui/js/popup.js +++ b/modules/system/assets/ui/js/popup.js @@ -395,7 +395,7 @@ if (typeof value == 'object') return value try { - return octoberJSON.parse("{" + value + "}") + return JSON.parse(JSON.stringify(eval("({" + value + "})"))) } catch (e) { throw new Error('Error parsing the '+name+' attribute value. '+e) From c426920b6363e6af74b2c5de5832320fe2a55a08 Mon Sep 17 00:00:00 2001 From: Ayumi Hamasaki <46076483+ayumihamasaki2@users.noreply.github.com> Date: Mon, 12 Aug 2019 14:12:12 +0100 Subject: [PATCH 7/9] Revert "Revert "Add a small JSON Parser to October framework lib"" This reverts commit 86a0b49d947b2e8049aaafe8745e4e0215198374. --- .../assets/js/october.relation.js | 2 +- .../widgets/form/assets/js/october.form.js | 2 +- modules/system/assets/js/framework-min.js | 2 +- .../assets/js/framework.combined-min.js | 4 +- .../system/assets/js/framework.combined.js | 1 + modules/system/assets/js/framework.extras.js | 354 ++++++++++++++++++ modules/system/assets/js/framework.js | 5 +- modules/system/assets/js/october.parser.js | 353 +++++++++++++++++ modules/system/assets/ui/js/autocomplete.js | 2 +- modules/system/assets/ui/js/chart.line.js | 2 +- modules/system/assets/ui/js/popup.js | 2 +- 11 files changed, 720 insertions(+), 9 deletions(-) create mode 100644 modules/system/assets/js/october.parser.js diff --git a/modules/backend/behaviors/relationcontroller/assets/js/october.relation.js b/modules/backend/behaviors/relationcontroller/assets/js/october.relation.js index 80bf1bea4e..b5123ed001 100644 --- a/modules/backend/behaviors/relationcontroller/assets/js/october.relation.js +++ b/modules/backend/behaviors/relationcontroller/assets/js/october.relation.js @@ -87,7 +87,7 @@ if (typeof value == 'object') return value try { - return JSON.parse(JSON.stringify(eval("({" + value + "})"))) + return octoberJSON.parse("{" + value + "}") } catch (e) { throw new Error('Error parsing the '+name+' attribute value. '+e) diff --git a/modules/backend/widgets/form/assets/js/october.form.js b/modules/backend/widgets/form/assets/js/october.form.js index 0936d2df35..237f12d2b5 100644 --- a/modules/backend/widgets/form/assets/js/october.form.js +++ b/modules/backend/widgets/form/assets/js/october.form.js @@ -264,7 +264,7 @@ if (typeof value == 'object') return value try { - return JSON.parse(JSON.stringify(eval("({" + value + "})"))) + return octoberJSON.parse("{" + value + "}") } catch (e) { throw new Error('Error parsing the '+name+' attribute value. '+e) diff --git a/modules/system/assets/js/framework-min.js b/modules/system/assets/js/framework-min.js index 94fa3dc967..d099053d3e 100644 --- a/modules/system/assets/js/framework-min.js +++ b/modules/system/assets/js/framework-min.js @@ -1,4 +1,4 @@ - +"use strict";!function(){function a(e,r,n){for(var t="",o=r;o= "0" && str[pos] <= "9")) { + var body = ""; + for (var i = pos; i < str.length; i++) { + if (str[i] === "-" || str[i] === "+" || str[i] === "." || (str[i] >= "0" && str[i] <= "9")) { + body += str[i]; + } else { + return { + originLength: body.length, + body: body + }; + } + } + throw new Error("Broken JSON number body near " + body); + } + + // parse object + if (str[pos] === "{" || str[pos] === "[") { + var stack = [str[pos]]; + var body = str[pos]; + for (var i = pos + 1; i < str.length; i++) { + body += str[i]; + if (str[i] === "\\") { + if (i + 1 < str.length) body += str[i + 1]; + i++; + } else if (str[i] === "\"") { + if (stack[stack.length - 1] === "\"") { + stack.pop(); + } else if (stack[stack.length - 1] !== "'") { + stack.push(str[i]); + } + } else if (str[i] === "'") { + if (stack[stack.length - 1] === "'") { + stack.pop(); + } else if (stack[stack.length - 1] !== "\"") { + stack.push(str[i]); + } + } else if (stack[stack.length - 1] !== "\"" && stack[stack.length - 1] !== "'") { + if (str[i] === "{") { + stack.push("{"); + } else if (str[i] === "}") { + if (stack[stack.length - 1] === "{") { + stack.pop(); + } else { + throw new Error("Broken JSON " + (str[pos] === "{" ? "object" : "array") + " body near " + body); + } + } else if (str[i] === "[") { + stack.push("["); + } else if (str[i] === "]") { + if (stack[stack.length - 1] === "[") { + stack.pop(); + } else { + throw new Error("Broken JSON " + (str[pos] === "{" ? "object" : "array") + " body near " + body); + } + } + } + if (!stack.length) { + return { + originLength: i - pos, + body: body + }; + } + } + throw new Error("Broken JSON " + (str[pos] === "{" ? "object" : "array") + " body near " + body); + } + throw new Error("Broken JSON body near " + str.substr((pos - 5 >= 0) ? pos - 5 : 0, 50)); + } + + /* + * This is a char can be key head + * @param ch + * @returns {boolean} + */ + function canBeKeyHead(ch) { + if (ch[0] === "\\") return false; + if ((ch[0] >= 'a' && ch[0] <= 'z') || (ch[0] >= 'A' && ch[0] <= 'Z') || ch[0] === '_') return true; + if (ch[0] >= '0' && ch[0] <= '9') return true; + if (ch[0] === '$') return true; + if (ch.charCodeAt(0) > 255) return true; + return false; + } + + function isBlankChar(ch) { + return ch === " " || ch === "\n" || ch === "\t"; + } + + /* + * parse JSON + * @param str + */ + function parse(str) { + str = str.trim(); + if (!str.length) throw new Error("Broken JSON object."); + var result = ""; + + /* + * the mistake ',' + */ + while (str && str[0] === ",") { + str = str.substr(1); + } + + /* + * string + */ + if (str[0] === "\"" || str[0] === "'") { + if (str[str.length - 1] !== str[0]) { + throw new Error("Invalid string JSON object."); + } + + var body = "\""; + for (var i = 1; i < str.length; i++) { + if (str[i] === "\\") { + if (str[i + 1] === "'") { + body += str[i + 1] + } else { + body += str[i]; + body += str[i + 1]; + } + i++; + } else if (str[i] === str[0]) { + body += "\""; + return body + } else if (str[i] === "\"") { + body += "\\\"" + } else body += str[i]; + } + throw new Error("Invalid string JSON object."); + } + + /* + * boolean + */ + if (str === "true" || str === "false") { + return str; + } + + /* + * null + */ + if (str === "null") { + return "null"; + } + + /* + * number + */ + var num = parseFloat(str); + if (!isNaN(num)) { + return num.toString(); + } + + /* + * object + */ + if (str[0] === "{") { + var type = "needKey"; + var result = "{"; + + for (var i = 1; i < str.length; i++) { + if (isBlankChar(str[i])) { + continue; + } else if (type === "needKey" && (str[i] === "\"" || str[i] === "'")) { + var key = parseKey(str, i + 1, str[i]); + result += "\"" + key + "\""; + i += key.length; + i += 1; + type = "afterKey"; + } else if (type === "needKey" && canBeKeyHead(str[i])) { + var key = parseKey(str, i); + result += "\""; + result += key; + result += "\""; + i += key.length - 1; + type = "afterKey"; + } else if (type === "afterKey" && str[i] === ":") { + result += ":"; + type = ":"; + } else if (type === ":") { + var body = getBody(str, i); + + i = i + body.originLength - 1; + result += parse(body.body); + + type = "afterBody"; + } else if (type === "afterBody" || type === "needKey") { + var last = i; + while (str[last] === "," || isBlankChar(str[last])) { + last++; + } + if (str[last] === "}" && last === str.length - 1) { + while (result[result.length - 1] === ",") { + result = result.substr(0, result.length - 1); + } + result += "}"; + return result; + } else if (last !== i && result !== "{") { + result += ","; + type = "needKey"; + i = last - 1; + } + } + } + throw new Error("Broken JSON object near " + result); + } + + /* + * array + */ + if (str[0] === "[") { + var result = "["; + var type = "needBody"; + for (var i = 1; i < str.length; i++) { + if (" " === str[i] || "\n" === str[i] || "\t" === str[i]) { + continue; + } else if (type === "needBody") { + if (str[i] === ",") { + result += "null,"; + continue; + } + if (str[i] === "]" && i === str.length - 1) { + if (result[result.length - 1] === ",") result = result.substr(0, result.length - 1); + result += "]"; + return result; + } + + var body = getBody(str, i); + + i = i + body.originLength - 1; + result += parse(body.body); + + type = "afterBody"; + } else if (type === "afterBody") { + if (str[i] === ",") { + result += ","; + type = "needBody"; + + // deal with mistake "," + while (str[i + 1] === "," || isBlankChar(str[i + 1])) { + if (str[i + 1] === ",") result += "null,"; + i++; + } + } else if (str[i] === "]" && i === str.length - 1) { + result += "]"; + return result; + } + } + } + throw new Error("Broken JSON array near " + result); + } + } + + var g = (typeof exports === "undefined") ? (window.octoberJSON = {}) : exports; + + /* + * parse October JSON string into JSON object + * @param json + * @returns {*} + */ + g.parse = function(json) { + var jsonString = parse(json); + return JSON.parse(jsonString); + }; +})(); + +function ($) { "use strict"; if ($.oc === undefined) $.oc = {} diff --git a/modules/system/assets/js/framework.js b/modules/system/assets/js/framework.js index 4330d18be3..bfc7aaf4af 100644 --- a/modules/system/assets/js/framework.js +++ b/modules/system/assets/js/framework.js @@ -5,6 +5,9 @@ * Copyright 2017 Alexey Bobkov, Samuel Georges * ======================================================================== */ +/* October CMS JSON Parser */ +"use strict";!function(){function a(e,r,n){for(var t="",o=r;o= "0" && str[pos] <= "9")) { + var body = ""; + for (var i = pos; i < str.length; i++) { + if (str[i] === "-" || str[i] === "+" || str[i] === "." || (str[i] >= "0" && str[i] <= "9")) { + body += str[i]; + } else { + return { + originLength: body.length, + body: body + }; + } + } + throw new Error("Broken JSON number body near " + body); + } + + // parse object + if (str[pos] === "{" || str[pos] === "[") { + var stack = [str[pos]]; + var body = str[pos]; + for (var i = pos + 1; i < str.length; i++) { + body += str[i]; + if (str[i] === "\\") { + if (i + 1 < str.length) body += str[i + 1]; + i++; + } else if (str[i] === "\"") { + if (stack[stack.length - 1] === "\"") { + stack.pop(); + } else if (stack[stack.length - 1] !== "'") { + stack.push(str[i]); + } + } else if (str[i] === "'") { + if (stack[stack.length - 1] === "'") { + stack.pop(); + } else if (stack[stack.length - 1] !== "\"") { + stack.push(str[i]); + } + } else if (stack[stack.length - 1] !== "\"" && stack[stack.length - 1] !== "'") { + if (str[i] === "{") { + stack.push("{"); + } else if (str[i] === "}") { + if (stack[stack.length - 1] === "{") { + stack.pop(); + } else { + throw new Error("Broken JSON " + (str[pos] === "{" ? "object" : "array") + " body near " + body); + } + } else if (str[i] === "[") { + stack.push("["); + } else if (str[i] === "]") { + if (stack[stack.length - 1] === "[") { + stack.pop(); + } else { + throw new Error("Broken JSON " + (str[pos] === "{" ? "object" : "array") + " body near " + body); + } + } + } + if (!stack.length) { + return { + originLength: i - pos, + body: body + }; + } + } + throw new Error("Broken JSON " + (str[pos] === "{" ? "object" : "array") + " body near " + body); + } + throw new Error("Broken JSON body near " + str.substr((pos - 5 >= 0) ? pos - 5 : 0, 50)); + } + + /* + * This is a char can be key head + * @param ch + * @returns {boolean} + */ + function canBeKeyHead(ch) { + if (ch[0] === "\\") return false; + if ((ch[0] >= 'a' && ch[0] <= 'z') || (ch[0] >= 'A' && ch[0] <= 'Z') || ch[0] === '_') return true; + if (ch[0] >= '0' && ch[0] <= '9') return true; + if (ch[0] === '$') return true; + if (ch.charCodeAt(0) > 255) return true; + return false; + } + + function isBlankChar(ch) { + return ch === " " || ch === "\n" || ch === "\t"; + } + + /* + * parse JSON + * @param str + */ + function parse(str) { + str = str.trim(); + if (!str.length) throw new Error("Broken JSON object."); + var result = ""; + + /* + * the mistake ',' + */ + while (str && str[0] === ",") { + str = str.substr(1); + } + + /* + * string + */ + if (str[0] === "\"" || str[0] === "'") { + if (str[str.length - 1] !== str[0]) { + throw new Error("Invalid string JSON object."); + } + + var body = "\""; + for (var i = 1; i < str.length; i++) { + if (str[i] === "\\") { + if (str[i + 1] === "'") { + body += str[i + 1] + } else { + body += str[i]; + body += str[i + 1]; + } + i++; + } else if (str[i] === str[0]) { + body += "\""; + return body + } else if (str[i] === "\"") { + body += "\\\"" + } else body += str[i]; + } + throw new Error("Invalid string JSON object."); + } + + /* + * boolean + */ + if (str === "true" || str === "false") { + return str; + } + + /* + * null + */ + if (str === "null") { + return "null"; + } + + /* + * number + */ + var num = parseFloat(str); + if (!isNaN(num)) { + return num.toString(); + } + + /* + * object + */ + if (str[0] === "{") { + var type = "needKey"; + var result = "{"; + + for (var i = 1; i < str.length; i++) { + if (isBlankChar(str[i])) { + continue; + } else if (type === "needKey" && (str[i] === "\"" || str[i] === "'")) { + var key = parseKey(str, i + 1, str[i]); + result += "\"" + key + "\""; + i += key.length; + i += 1; + type = "afterKey"; + } else if (type === "needKey" && canBeKeyHead(str[i])) { + var key = parseKey(str, i); + result += "\""; + result += key; + result += "\""; + i += key.length - 1; + type = "afterKey"; + } else if (type === "afterKey" && str[i] === ":") { + result += ":"; + type = ":"; + } else if (type === ":") { + var body = getBody(str, i); + + i = i + body.originLength - 1; + result += parse(body.body); + + type = "afterBody"; + } else if (type === "afterBody" || type === "needKey") { + var last = i; + while (str[last] === "," || isBlankChar(str[last])) { + last++; + } + if (str[last] === "}" && last === str.length - 1) { + while (result[result.length - 1] === ",") { + result = result.substr(0, result.length - 1); + } + result += "}"; + return result; + } else if (last !== i && result !== "{") { + result += ","; + type = "needKey"; + i = last - 1; + } + } + } + throw new Error("Broken JSON object near " + result); + } + + /* + * array + */ + if (str[0] === "[") { + var result = "["; + var type = "needBody"; + for (var i = 1; i < str.length; i++) { + if (" " === str[i] || "\n" === str[i] || "\t" === str[i]) { + continue; + } else if (type === "needBody") { + if (str[i] === ",") { + result += "null,"; + continue; + } + if (str[i] === "]" && i === str.length - 1) { + if (result[result.length - 1] === ",") result = result.substr(0, result.length - 1); + result += "]"; + return result; + } + + var body = getBody(str, i); + + i = i + body.originLength - 1; + result += parse(body.body); + + type = "afterBody"; + } else if (type === "afterBody") { + if (str[i] === ",") { + result += ","; + type = "needBody"; + + // deal with mistake "," + while (str[i + 1] === "," || isBlankChar(str[i + 1])) { + if (str[i + 1] === ",") result += "null,"; + i++; + } + } else if (str[i] === "]" && i === str.length - 1) { + result += "]"; + return result; + } + } + } + throw new Error("Broken JSON array near " + result); + } + } + + var g = (typeof exports === "undefined") ? (window.octoberJSON = {}) : exports; + + /* + * parse October JSON string into JSON object + * @param json + * @returns {*} + */ + g.parse = function(json) { + var jsonString = parse(json); + return JSON.parse(jsonString); + }; +})(); \ No newline at end of file diff --git a/modules/system/assets/ui/js/autocomplete.js b/modules/system/assets/ui/js/autocomplete.js index 59d2b96892..331e7a8eeb 100644 --- a/modules/system/assets/ui/js/autocomplete.js +++ b/modules/system/assets/ui/js/autocomplete.js @@ -378,7 +378,7 @@ if (typeof value == 'object') return value try { - return JSON.parse(JSON.stringify(eval("({" + value + "})"))) + return octoberJSON.parse("{" + value + "}") } catch (e) { throw new Error('Error parsing the '+name+' attribute value. '+e) diff --git a/modules/system/assets/ui/js/chart.line.js b/modules/system/assets/ui/js/chart.line.js index f89b412fab..ea03d3bacb 100644 --- a/modules/system/assets/ui/js/chart.line.js +++ b/modules/system/assets/ui/js/chart.line.js @@ -80,7 +80,7 @@ var parsedOptions = {} try { - parsedOptions = JSON.parse(JSON.stringify(eval("({" + options.chartOptions + "})"))); + parsedOptions = octoberJSON.parse("{" + value + "}"); } catch (e) { throw new Error('Error parsing the data-chart-options attribute value. '+e); } diff --git a/modules/system/assets/ui/js/popup.js b/modules/system/assets/ui/js/popup.js index 2ba8f348ec..570c9bbfa7 100644 --- a/modules/system/assets/ui/js/popup.js +++ b/modules/system/assets/ui/js/popup.js @@ -395,7 +395,7 @@ if (typeof value == 'object') return value try { - return JSON.parse(JSON.stringify(eval("({" + value + "})"))) + return octoberJSON.parse("{" + value + "}") } catch (e) { throw new Error('Error parsing the '+name+' attribute value. '+e) From d030ddc4f6bb27072230587f4b2519655e7f38b1 Mon Sep 17 00:00:00 2001 From: Ayumi Hamasaki <46076483+ayumihamasaki2@users.noreply.github.com> Date: Mon, 12 Aug 2019 14:12:49 +0100 Subject: [PATCH 8/9] Revert "Revert "Revert "Add a small JSON Parser to October framework lib""" This reverts commit c426920b6363e6af74b2c5de5832320fe2a55a08. --- .../assets/js/october.relation.js | 2 +- .../widgets/form/assets/js/october.form.js | 2 +- modules/system/assets/js/framework-min.js | 2 +- .../assets/js/framework.combined-min.js | 4 +- .../system/assets/js/framework.combined.js | 1 - modules/system/assets/js/framework.extras.js | 354 ------------------ modules/system/assets/js/framework.js | 5 +- modules/system/assets/js/october.parser.js | 353 ----------------- modules/system/assets/ui/js/autocomplete.js | 2 +- modules/system/assets/ui/js/chart.line.js | 2 +- modules/system/assets/ui/js/popup.js | 2 +- 11 files changed, 9 insertions(+), 720 deletions(-) delete mode 100644 modules/system/assets/js/october.parser.js diff --git a/modules/backend/behaviors/relationcontroller/assets/js/october.relation.js b/modules/backend/behaviors/relationcontroller/assets/js/october.relation.js index b5123ed001..80bf1bea4e 100644 --- a/modules/backend/behaviors/relationcontroller/assets/js/october.relation.js +++ b/modules/backend/behaviors/relationcontroller/assets/js/october.relation.js @@ -87,7 +87,7 @@ if (typeof value == 'object') return value try { - return octoberJSON.parse("{" + value + "}") + return JSON.parse(JSON.stringify(eval("({" + value + "})"))) } catch (e) { throw new Error('Error parsing the '+name+' attribute value. '+e) diff --git a/modules/backend/widgets/form/assets/js/october.form.js b/modules/backend/widgets/form/assets/js/october.form.js index 237f12d2b5..0936d2df35 100644 --- a/modules/backend/widgets/form/assets/js/october.form.js +++ b/modules/backend/widgets/form/assets/js/october.form.js @@ -264,7 +264,7 @@ if (typeof value == 'object') return value try { - return octoberJSON.parse("{" + value + "}") + return JSON.parse(JSON.stringify(eval("({" + value + "})"))) } catch (e) { throw new Error('Error parsing the '+name+' attribute value. '+e) diff --git a/modules/system/assets/js/framework-min.js b/modules/system/assets/js/framework-min.js index d099053d3e..94fa3dc967 100644 --- a/modules/system/assets/js/framework-min.js +++ b/modules/system/assets/js/framework-min.js @@ -1,4 +1,4 @@ -"use strict";!function(){function a(e,r,n){for(var t="",o=r;o= "0" && str[pos] <= "9")) { - var body = ""; - for (var i = pos; i < str.length; i++) { - if (str[i] === "-" || str[i] === "+" || str[i] === "." || (str[i] >= "0" && str[i] <= "9")) { - body += str[i]; - } else { - return { - originLength: body.length, - body: body - }; - } - } - throw new Error("Broken JSON number body near " + body); - } - - // parse object - if (str[pos] === "{" || str[pos] === "[") { - var stack = [str[pos]]; - var body = str[pos]; - for (var i = pos + 1; i < str.length; i++) { - body += str[i]; - if (str[i] === "\\") { - if (i + 1 < str.length) body += str[i + 1]; - i++; - } else if (str[i] === "\"") { - if (stack[stack.length - 1] === "\"") { - stack.pop(); - } else if (stack[stack.length - 1] !== "'") { - stack.push(str[i]); - } - } else if (str[i] === "'") { - if (stack[stack.length - 1] === "'") { - stack.pop(); - } else if (stack[stack.length - 1] !== "\"") { - stack.push(str[i]); - } - } else if (stack[stack.length - 1] !== "\"" && stack[stack.length - 1] !== "'") { - if (str[i] === "{") { - stack.push("{"); - } else if (str[i] === "}") { - if (stack[stack.length - 1] === "{") { - stack.pop(); - } else { - throw new Error("Broken JSON " + (str[pos] === "{" ? "object" : "array") + " body near " + body); - } - } else if (str[i] === "[") { - stack.push("["); - } else if (str[i] === "]") { - if (stack[stack.length - 1] === "[") { - stack.pop(); - } else { - throw new Error("Broken JSON " + (str[pos] === "{" ? "object" : "array") + " body near " + body); - } - } - } - if (!stack.length) { - return { - originLength: i - pos, - body: body - }; - } - } - throw new Error("Broken JSON " + (str[pos] === "{" ? "object" : "array") + " body near " + body); - } - throw new Error("Broken JSON body near " + str.substr((pos - 5 >= 0) ? pos - 5 : 0, 50)); - } - - /* - * This is a char can be key head - * @param ch - * @returns {boolean} - */ - function canBeKeyHead(ch) { - if (ch[0] === "\\") return false; - if ((ch[0] >= 'a' && ch[0] <= 'z') || (ch[0] >= 'A' && ch[0] <= 'Z') || ch[0] === '_') return true; - if (ch[0] >= '0' && ch[0] <= '9') return true; - if (ch[0] === '$') return true; - if (ch.charCodeAt(0) > 255) return true; - return false; - } - - function isBlankChar(ch) { - return ch === " " || ch === "\n" || ch === "\t"; - } - - /* - * parse JSON - * @param str - */ - function parse(str) { - str = str.trim(); - if (!str.length) throw new Error("Broken JSON object."); - var result = ""; - - /* - * the mistake ',' - */ - while (str && str[0] === ",") { - str = str.substr(1); - } - - /* - * string - */ - if (str[0] === "\"" || str[0] === "'") { - if (str[str.length - 1] !== str[0]) { - throw new Error("Invalid string JSON object."); - } - - var body = "\""; - for (var i = 1; i < str.length; i++) { - if (str[i] === "\\") { - if (str[i + 1] === "'") { - body += str[i + 1] - } else { - body += str[i]; - body += str[i + 1]; - } - i++; - } else if (str[i] === str[0]) { - body += "\""; - return body - } else if (str[i] === "\"") { - body += "\\\"" - } else body += str[i]; - } - throw new Error("Invalid string JSON object."); - } - - /* - * boolean - */ - if (str === "true" || str === "false") { - return str; - } - - /* - * null - */ - if (str === "null") { - return "null"; - } - - /* - * number - */ - var num = parseFloat(str); - if (!isNaN(num)) { - return num.toString(); - } - - /* - * object - */ - if (str[0] === "{") { - var type = "needKey"; - var result = "{"; - - for (var i = 1; i < str.length; i++) { - if (isBlankChar(str[i])) { - continue; - } else if (type === "needKey" && (str[i] === "\"" || str[i] === "'")) { - var key = parseKey(str, i + 1, str[i]); - result += "\"" + key + "\""; - i += key.length; - i += 1; - type = "afterKey"; - } else if (type === "needKey" && canBeKeyHead(str[i])) { - var key = parseKey(str, i); - result += "\""; - result += key; - result += "\""; - i += key.length - 1; - type = "afterKey"; - } else if (type === "afterKey" && str[i] === ":") { - result += ":"; - type = ":"; - } else if (type === ":") { - var body = getBody(str, i); - - i = i + body.originLength - 1; - result += parse(body.body); - - type = "afterBody"; - } else if (type === "afterBody" || type === "needKey") { - var last = i; - while (str[last] === "," || isBlankChar(str[last])) { - last++; - } - if (str[last] === "}" && last === str.length - 1) { - while (result[result.length - 1] === ",") { - result = result.substr(0, result.length - 1); - } - result += "}"; - return result; - } else if (last !== i && result !== "{") { - result += ","; - type = "needKey"; - i = last - 1; - } - } - } - throw new Error("Broken JSON object near " + result); - } - - /* - * array - */ - if (str[0] === "[") { - var result = "["; - var type = "needBody"; - for (var i = 1; i < str.length; i++) { - if (" " === str[i] || "\n" === str[i] || "\t" === str[i]) { - continue; - } else if (type === "needBody") { - if (str[i] === ",") { - result += "null,"; - continue; - } - if (str[i] === "]" && i === str.length - 1) { - if (result[result.length - 1] === ",") result = result.substr(0, result.length - 1); - result += "]"; - return result; - } - - var body = getBody(str, i); - - i = i + body.originLength - 1; - result += parse(body.body); - - type = "afterBody"; - } else if (type === "afterBody") { - if (str[i] === ",") { - result += ","; - type = "needBody"; - - // deal with mistake "," - while (str[i + 1] === "," || isBlankChar(str[i + 1])) { - if (str[i + 1] === ",") result += "null,"; - i++; - } - } else if (str[i] === "]" && i === str.length - 1) { - result += "]"; - return result; - } - } - } - throw new Error("Broken JSON array near " + result); - } - } - - var g = (typeof exports === "undefined") ? (window.octoberJSON = {}) : exports; - - /* - * parse October JSON string into JSON object - * @param json - * @returns {*} - */ - g.parse = function(json) { - var jsonString = parse(json); - return JSON.parse(jsonString); - }; -})(); - +function ($) { "use strict"; if ($.oc === undefined) $.oc = {} diff --git a/modules/system/assets/js/framework.js b/modules/system/assets/js/framework.js index bfc7aaf4af..4330d18be3 100644 --- a/modules/system/assets/js/framework.js +++ b/modules/system/assets/js/framework.js @@ -5,9 +5,6 @@ * Copyright 2017 Alexey Bobkov, Samuel Georges * ======================================================================== */ -/* October CMS JSON Parser */ -"use strict";!function(){function a(e,r,n){for(var t="",o=r;o= "0" && str[pos] <= "9")) { - var body = ""; - for (var i = pos; i < str.length; i++) { - if (str[i] === "-" || str[i] === "+" || str[i] === "." || (str[i] >= "0" && str[i] <= "9")) { - body += str[i]; - } else { - return { - originLength: body.length, - body: body - }; - } - } - throw new Error("Broken JSON number body near " + body); - } - - // parse object - if (str[pos] === "{" || str[pos] === "[") { - var stack = [str[pos]]; - var body = str[pos]; - for (var i = pos + 1; i < str.length; i++) { - body += str[i]; - if (str[i] === "\\") { - if (i + 1 < str.length) body += str[i + 1]; - i++; - } else if (str[i] === "\"") { - if (stack[stack.length - 1] === "\"") { - stack.pop(); - } else if (stack[stack.length - 1] !== "'") { - stack.push(str[i]); - } - } else if (str[i] === "'") { - if (stack[stack.length - 1] === "'") { - stack.pop(); - } else if (stack[stack.length - 1] !== "\"") { - stack.push(str[i]); - } - } else if (stack[stack.length - 1] !== "\"" && stack[stack.length - 1] !== "'") { - if (str[i] === "{") { - stack.push("{"); - } else if (str[i] === "}") { - if (stack[stack.length - 1] === "{") { - stack.pop(); - } else { - throw new Error("Broken JSON " + (str[pos] === "{" ? "object" : "array") + " body near " + body); - } - } else if (str[i] === "[") { - stack.push("["); - } else if (str[i] === "]") { - if (stack[stack.length - 1] === "[") { - stack.pop(); - } else { - throw new Error("Broken JSON " + (str[pos] === "{" ? "object" : "array") + " body near " + body); - } - } - } - if (!stack.length) { - return { - originLength: i - pos, - body: body - }; - } - } - throw new Error("Broken JSON " + (str[pos] === "{" ? "object" : "array") + " body near " + body); - } - throw new Error("Broken JSON body near " + str.substr((pos - 5 >= 0) ? pos - 5 : 0, 50)); - } - - /* - * This is a char can be key head - * @param ch - * @returns {boolean} - */ - function canBeKeyHead(ch) { - if (ch[0] === "\\") return false; - if ((ch[0] >= 'a' && ch[0] <= 'z') || (ch[0] >= 'A' && ch[0] <= 'Z') || ch[0] === '_') return true; - if (ch[0] >= '0' && ch[0] <= '9') return true; - if (ch[0] === '$') return true; - if (ch.charCodeAt(0) > 255) return true; - return false; - } - - function isBlankChar(ch) { - return ch === " " || ch === "\n" || ch === "\t"; - } - - /* - * parse JSON - * @param str - */ - function parse(str) { - str = str.trim(); - if (!str.length) throw new Error("Broken JSON object."); - var result = ""; - - /* - * the mistake ',' - */ - while (str && str[0] === ",") { - str = str.substr(1); - } - - /* - * string - */ - if (str[0] === "\"" || str[0] === "'") { - if (str[str.length - 1] !== str[0]) { - throw new Error("Invalid string JSON object."); - } - - var body = "\""; - for (var i = 1; i < str.length; i++) { - if (str[i] === "\\") { - if (str[i + 1] === "'") { - body += str[i + 1] - } else { - body += str[i]; - body += str[i + 1]; - } - i++; - } else if (str[i] === str[0]) { - body += "\""; - return body - } else if (str[i] === "\"") { - body += "\\\"" - } else body += str[i]; - } - throw new Error("Invalid string JSON object."); - } - - /* - * boolean - */ - if (str === "true" || str === "false") { - return str; - } - - /* - * null - */ - if (str === "null") { - return "null"; - } - - /* - * number - */ - var num = parseFloat(str); - if (!isNaN(num)) { - return num.toString(); - } - - /* - * object - */ - if (str[0] === "{") { - var type = "needKey"; - var result = "{"; - - for (var i = 1; i < str.length; i++) { - if (isBlankChar(str[i])) { - continue; - } else if (type === "needKey" && (str[i] === "\"" || str[i] === "'")) { - var key = parseKey(str, i + 1, str[i]); - result += "\"" + key + "\""; - i += key.length; - i += 1; - type = "afterKey"; - } else if (type === "needKey" && canBeKeyHead(str[i])) { - var key = parseKey(str, i); - result += "\""; - result += key; - result += "\""; - i += key.length - 1; - type = "afterKey"; - } else if (type === "afterKey" && str[i] === ":") { - result += ":"; - type = ":"; - } else if (type === ":") { - var body = getBody(str, i); - - i = i + body.originLength - 1; - result += parse(body.body); - - type = "afterBody"; - } else if (type === "afterBody" || type === "needKey") { - var last = i; - while (str[last] === "," || isBlankChar(str[last])) { - last++; - } - if (str[last] === "}" && last === str.length - 1) { - while (result[result.length - 1] === ",") { - result = result.substr(0, result.length - 1); - } - result += "}"; - return result; - } else if (last !== i && result !== "{") { - result += ","; - type = "needKey"; - i = last - 1; - } - } - } - throw new Error("Broken JSON object near " + result); - } - - /* - * array - */ - if (str[0] === "[") { - var result = "["; - var type = "needBody"; - for (var i = 1; i < str.length; i++) { - if (" " === str[i] || "\n" === str[i] || "\t" === str[i]) { - continue; - } else if (type === "needBody") { - if (str[i] === ",") { - result += "null,"; - continue; - } - if (str[i] === "]" && i === str.length - 1) { - if (result[result.length - 1] === ",") result = result.substr(0, result.length - 1); - result += "]"; - return result; - } - - var body = getBody(str, i); - - i = i + body.originLength - 1; - result += parse(body.body); - - type = "afterBody"; - } else if (type === "afterBody") { - if (str[i] === ",") { - result += ","; - type = "needBody"; - - // deal with mistake "," - while (str[i + 1] === "," || isBlankChar(str[i + 1])) { - if (str[i + 1] === ",") result += "null,"; - i++; - } - } else if (str[i] === "]" && i === str.length - 1) { - result += "]"; - return result; - } - } - } - throw new Error("Broken JSON array near " + result); - } - } - - var g = (typeof exports === "undefined") ? (window.octoberJSON = {}) : exports; - - /* - * parse October JSON string into JSON object - * @param json - * @returns {*} - */ - g.parse = function(json) { - var jsonString = parse(json); - return JSON.parse(jsonString); - }; -})(); \ No newline at end of file diff --git a/modules/system/assets/ui/js/autocomplete.js b/modules/system/assets/ui/js/autocomplete.js index 331e7a8eeb..59d2b96892 100644 --- a/modules/system/assets/ui/js/autocomplete.js +++ b/modules/system/assets/ui/js/autocomplete.js @@ -378,7 +378,7 @@ if (typeof value == 'object') return value try { - return octoberJSON.parse("{" + value + "}") + return JSON.parse(JSON.stringify(eval("({" + value + "})"))) } catch (e) { throw new Error('Error parsing the '+name+' attribute value. '+e) diff --git a/modules/system/assets/ui/js/chart.line.js b/modules/system/assets/ui/js/chart.line.js index ea03d3bacb..f89b412fab 100644 --- a/modules/system/assets/ui/js/chart.line.js +++ b/modules/system/assets/ui/js/chart.line.js @@ -80,7 +80,7 @@ var parsedOptions = {} try { - parsedOptions = octoberJSON.parse("{" + value + "}"); + parsedOptions = JSON.parse(JSON.stringify(eval("({" + options.chartOptions + "})"))); } catch (e) { throw new Error('Error parsing the data-chart-options attribute value. '+e); } diff --git a/modules/system/assets/ui/js/popup.js b/modules/system/assets/ui/js/popup.js index 570c9bbfa7..2ba8f348ec 100644 --- a/modules/system/assets/ui/js/popup.js +++ b/modules/system/assets/ui/js/popup.js @@ -395,7 +395,7 @@ if (typeof value == 'object') return value try { - return octoberJSON.parse("{" + value + "}") + return JSON.parse(JSON.stringify(eval("({" + value + "})"))) } catch (e) { throw new Error('Error parsing the '+name+' attribute value. '+e) From 4a4607c2932ef17480cd8523050014bd0f7eb520 Mon Sep 17 00:00:00 2001 From: Ayumi Hamasaki <46076483+ayumihamasaki2@users.noreply.github.com> Date: Mon, 26 Aug 2019 23:41:20 +0100 Subject: [PATCH 9/9] Update jQuery mousewheel --- .../assets/ui/vendor/mousewheel/mousewheel.js | 157 +++++++++++------- 1 file changed, 97 insertions(+), 60 deletions(-) diff --git a/modules/system/assets/ui/vendor/mousewheel/mousewheel.js b/modules/system/assets/ui/vendor/mousewheel/mousewheel.js index a515e7e6a5..c50151a9ef 100644 --- a/modules/system/assets/ui/vendor/mousewheel/mousewheel.js +++ b/modules/system/assets/ui/vendor/mousewheel/mousewheel.js @@ -1,104 +1,124 @@ -/*! Copyright (c) 2013 Brandon Aaron (http://brandon.aaron.sh) - * Licensed under the MIT License (LICENSE.txt). - * - * Version: 3.1.9 - * - * Requires: jQuery 1.2.2+ +/*! + * jQuery Mousewheel v3.2.0 + * https://github.com/jquery/jquery-mousewheel */ -(function (factory) { - if ( typeof define === 'function' && define.amd ) { +( function( factory ) { + if ( typeof define === "function" && define.amd ) { + // AMD. Register as an anonymous module. - define(['jquery'], factory); - } else if (typeof exports === 'object') { + define( [ "jquery" ], factory ); + } else if ( typeof exports === "object" ) { + // Node/CommonJS style for Browserify module.exports = factory; } else { + // Browser globals - factory(jQuery); + factory( jQuery ); } -}(function ($) { +} )( function( $ ) { - var toFix = ['wheel', 'mousewheel', 'DOMMouseScroll', 'MozMousePixelScroll'], - toBind = ( 'onwheel' in document || document.documentMode >= 9 ) ? - ['wheel'] : ['mousewheel', 'DomMouseScroll', 'MozMousePixelScroll'], + var toFix = [ "wheel", "mousewheel", "DOMMouseScroll", "MozMousePixelScroll" ], + toBind = ( "onwheel" in window.document || window.document.documentMode >= 9 ) ? + [ "wheel" ] : [ "mousewheel", "DomMouseScroll", "MozMousePixelScroll" ], slice = Array.prototype.slice, nullLowestDeltaTimeout, lowestDelta; if ( $.event.fixHooks ) { for ( var i = toFix.length; i; ) { - $.event.fixHooks[ toFix[--i] ] = $.event.mouseHooks; + $.event.fixHooks[ toFix[ --i ] ] = $.event.mouseHooks; } } var special = $.event.special.mousewheel = { - version: '3.1.9', + version: "3.2.0", setup: function() { if ( this.addEventListener ) { for ( var i = toBind.length; i; ) { - this.addEventListener( toBind[--i], handler, false ); + this.addEventListener( toBind[ --i ], handler, false ); } } else { this.onmousewheel = handler; } + // Store the line height and page height for this particular element - $.data(this, 'mousewheel-line-height', special.getLineHeight(this)); - $.data(this, 'mousewheel-page-height', special.getPageHeight(this)); + $.data( this, "mousewheel-line-height", special.getLineHeight( this ) ); + $.data( this, "mousewheel-page-height", special.getPageHeight( this ) ); }, teardown: function() { if ( this.removeEventListener ) { for ( var i = toBind.length; i; ) { - this.removeEventListener( toBind[--i], handler, false ); + this.removeEventListener( toBind[ --i ], handler, false ); } } else { this.onmousewheel = null; } + + // Clean up the data we added to the element + $.removeData( this, "mousewheel-line-height" ); + $.removeData( this, "mousewheel-page-height" ); }, - getLineHeight: function(elem) { - return parseInt($(elem)['offsetParent' in $.fn ? 'offsetParent' : 'parent']().css('fontSize'), 10); + getLineHeight: function( elem ) { + var $elem = $( elem ), + $parent = $elem[ "offsetParent" in $.fn ? "offsetParent" : "parent" ](); + if ( !$parent.length ) { + $parent = $( "body" ); + } + return parseInt( $parent.css( "fontSize" ), 10 ) || + parseInt( $elem.css( "fontSize" ), 10 ) || 16; }, - getPageHeight: function(elem) { - return $(elem).height(); + getPageHeight: function( elem ) { + return $( elem ).height(); }, settings: { - adjustOldDeltas: true + adjustOldDeltas: true, // see shouldAdjustOldDeltas() below + normalizeOffset: true // calls getBoundingClientRect for each event } }; - $.fn.extend({ - mousewheel: function(fn) { - return fn ? this.bind('mousewheel', fn) : this.trigger('mousewheel'); + $.fn.extend( { + mousewheel: function( fn ) { + return fn ? this.on( "mousewheel", fn ) : this.trigger( "mousewheel" ); }, - unmousewheel: function(fn) { - return this.unbind('mousewheel', fn); + unmousewheel: function( fn ) { + return this.off( "mousewheel", fn ); } - }); + } ); - function handler(event) { + function handler( event ) { var orgEvent = event || window.event, - args = slice.call(arguments, 1), + args = slice.call( arguments, 1 ), delta = 0, deltaX = 0, deltaY = 0, absDelta = 0; - event = $.event.fix(orgEvent); - event.type = 'mousewheel'; + event = $.event.fix( orgEvent ); + event.type = "mousewheel"; // Old school scrollwheel delta - if ( 'detail' in orgEvent ) { deltaY = orgEvent.detail * -1; } - if ( 'wheelDelta' in orgEvent ) { deltaY = orgEvent.wheelDelta; } - if ( 'wheelDeltaY' in orgEvent ) { deltaY = orgEvent.wheelDeltaY; } - if ( 'wheelDeltaX' in orgEvent ) { deltaX = orgEvent.wheelDeltaX * -1; } + if ( "detail" in orgEvent ) { + deltaY = orgEvent.detail * -1; + } + if ( "wheelDelta" in orgEvent ) { + deltaY = orgEvent.wheelDelta; + } + if ( "wheelDeltaY" in orgEvent ) { + deltaY = orgEvent.wheelDeltaY; + } + if ( "wheelDeltaX" in orgEvent ) { + deltaX = orgEvent.wheelDeltaX * -1; + } // Firefox < 17 horizontal scrolling related to DOMMouseScroll event - if ( 'axis' in orgEvent && orgEvent.axis === orgEvent.HORIZONTAL_AXIS ) { + if ( "axis" in orgEvent && orgEvent.axis === orgEvent.HORIZONTAL_AXIS ) { deltaX = deltaY * -1; deltaY = 0; } @@ -107,17 +127,21 @@ delta = deltaY === 0 ? deltaX : deltaY; // New school wheel delta (wheel event) - if ( 'deltaY' in orgEvent ) { + if ( "deltaY" in orgEvent ) { deltaY = orgEvent.deltaY * -1; delta = deltaY; } - if ( 'deltaX' in orgEvent ) { + if ( "deltaX" in orgEvent ) { deltaX = orgEvent.deltaX; - if ( deltaY === 0 ) { delta = deltaX * -1; } + if ( deltaY === 0 ) { + delta = deltaX * -1; + } } // No change actually happened, no reason to go any further - if ( deltaY === 0 && deltaX === 0 ) { return; } + if ( deltaY === 0 && deltaX === 0 ) { + return; + } // Need to convert lines and pages to pixels if we aren't already in pixels // There are three delta modes: @@ -125,31 +149,32 @@ // * deltaMode 1 is by lines // * deltaMode 2 is by pages if ( orgEvent.deltaMode === 1 ) { - var lineHeight = $.data(this, 'mousewheel-line-height'); + var lineHeight = $.data( this, "mousewheel-line-height" ); delta *= lineHeight; deltaY *= lineHeight; deltaX *= lineHeight; } else if ( orgEvent.deltaMode === 2 ) { - var pageHeight = $.data(this, 'mousewheel-page-height'); + var pageHeight = $.data( this, "mousewheel-page-height" ); delta *= pageHeight; deltaY *= pageHeight; deltaX *= pageHeight; } // Store lowest absolute delta to normalize the delta values - absDelta = Math.max( Math.abs(deltaY), Math.abs(deltaX) ); + absDelta = Math.max( Math.abs( deltaY ), Math.abs( deltaX ) ); if ( !lowestDelta || absDelta < lowestDelta ) { lowestDelta = absDelta; // Adjust older deltas if necessary - if ( shouldAdjustOldDeltas(orgEvent, absDelta) ) { + if ( shouldAdjustOldDeltas( orgEvent, absDelta ) ) { lowestDelta /= 40; } } // Adjust older deltas if necessary - if ( shouldAdjustOldDeltas(orgEvent, absDelta) ) { + if ( shouldAdjustOldDeltas( orgEvent, absDelta ) ) { + // Divide all the things by 40! delta /= 40; deltaX /= 40; @@ -157,37 +182,48 @@ } // Get a whole, normalized value for the deltas - delta = Math[ delta >= 1 ? 'floor' : 'ceil' ](delta / lowestDelta); - deltaX = Math[ deltaX >= 1 ? 'floor' : 'ceil' ](deltaX / lowestDelta); - deltaY = Math[ deltaY >= 1 ? 'floor' : 'ceil' ](deltaY / lowestDelta); + delta = Math[ delta >= 1 ? "floor" : "ceil" ]( delta / lowestDelta ); + deltaX = Math[ deltaX >= 1 ? "floor" : "ceil" ]( deltaX / lowestDelta ); + deltaY = Math[ deltaY >= 1 ? "floor" : "ceil" ]( deltaY / lowestDelta ); + + // Normalise offsetX and offsetY properties + if ( special.settings.normalizeOffset && this.getBoundingClientRect ) { + var boundingRect = this.getBoundingClientRect(); + event.offsetX = event.clientX - boundingRect.left; + event.offsetY = event.clientY - boundingRect.top; + } // Add information to the event object event.deltaX = deltaX; event.deltaY = deltaY; event.deltaFactor = lowestDelta; + // Go ahead and set deltaMode to 0 since we converted to pixels // Although this is a little odd since we overwrite the deltaX/Y // properties with normalized deltas. event.deltaMode = 0; // Add event and delta to the front of the arguments - args.unshift(event, delta, deltaX, deltaY); + args.unshift( event, delta, deltaX, deltaY ); // Clearout lowestDelta after sometime to better // handle multiple device types that give different // a different lowestDelta // Ex: trackpad = 3 and mouse wheel = 120 - if (nullLowestDeltaTimeout) { clearTimeout(nullLowestDeltaTimeout); } - nullLowestDeltaTimeout = setTimeout(nullLowestDelta, 200); + if ( nullLowestDeltaTimeout ) { + window.clearTimeout( nullLowestDeltaTimeout ); + } + nullLowestDeltaTimeout = window.setTimeout( nullLowestDelta, 200 ); - return ($.event.dispatch || $.event.handle).apply(this, args); + return ( $.event.dispatch || $.event.handle ).apply( this, args ); } function nullLowestDelta() { lowestDelta = null; } - function shouldAdjustOldDeltas(orgEvent, absDelta) { + function shouldAdjustOldDeltas( orgEvent, absDelta ) { + // If this is an older event and the delta is divisable by 120, // then we are assuming that the browser is treating this as an // older mouse wheel event and that we should divide the deltas @@ -195,7 +231,8 @@ // Side note, this actually impacts the reported scroll distance // in older browsers and can cause scrolling to be slower than native. // Turn this off by setting $.event.special.mousewheel.settings.adjustOldDeltas to false. - return special.settings.adjustOldDeltas && orgEvent.type === 'mousewheel' && absDelta % 120 === 0; + return special.settings.adjustOldDeltas && orgEvent.type === "mousewheel" && + absDelta % 120 === 0; } -})); \ No newline at end of file +} );