Browse Source

Parse array/objects inside attributes safely

pull/437/head
Artur Arseniev 9 years ago
parent
commit
0efe3b2490
  1. 4
      dist/grapes.min.js
  2. 2
      package.json
  3. 9
      src/parser/model/ParserHtml.js
  4. 2
      test/specs/parser/model/ParserHtml.js

4
dist/grapes.min.js

File diff suppressed because one or more lines are too long

2
package.json

@ -1,7 +1,7 @@
{ {
"name": "grapesjs", "name": "grapesjs",
"description": "Free and Open Source Web Builder Framework", "description": "Free and Open Source Web Builder Framework",
"version": "0.12.9", "version": "0.12.14",
"author": "Artur Arseniev", "author": "Artur Arseniev",
"license": "BSD-3-Clause", "license": "BSD-3-Clause",
"homepage": "http://grapesjs.com", "homepage": "http://grapesjs.com",

9
src/parser/model/ParserHtml.js

@ -114,8 +114,13 @@ module.exports = config => {
const lastChar = nodeValue && nodeValue.substr(valueLen - 1); const lastChar = nodeValue && nodeValue.substr(valueLen - 1);
nodeValue = nodeValue === 'true' ? true : nodeValue; nodeValue = nodeValue === 'true' ? true : nodeValue;
nodeValue = nodeValue === 'false' ? false : nodeValue; nodeValue = nodeValue === 'false' ? false : nodeValue;
nodeValue = (firstChar == '{' && lastChar == '}') || // Try to json parse where is possible
(firstChar == '[' && lastChar == ']') ? JSON.parse(nodeValue) : nodeValue; // I can get false positive here (eg. a selector '[data-attr]')
// so put it under try/catch and let fail silently
try {
nodeValue = (firstChar == '{' && lastChar == '}') ||
(firstChar == '[' && lastChar == ']') ? JSON.parse(nodeValue) : nodeValue;
} catch (e) {}
model[modelAttr] = nodeValue; model[modelAttr] = nodeValue;
} else { } else {
model.attributes[nodeName] = nodeValue; model.attributes[nodeName] = nodeValue;

2
test/specs/parser/model/ParserHtml.js

@ -5,7 +5,7 @@ const DomComponents = require('dom_components');
module.exports = { module.exports = {
run() { run() {
describe.only('ParserHtml', () => { describe('ParserHtml', () => {
var obj; var obj;
beforeEach(() => { beforeEach(() => {

Loading…
Cancel
Save