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",
"description": "Free and Open Source Web Builder Framework",
"version": "0.12.9",
"version": "0.12.14",
"author": "Artur Arseniev",
"license": "BSD-3-Clause",
"homepage": "http://grapesjs.com",

9
src/parser/model/ParserHtml.js

@ -114,8 +114,13 @@ module.exports = config => {
const lastChar = nodeValue && nodeValue.substr(valueLen - 1);
nodeValue = nodeValue === 'true' ? true : nodeValue;
nodeValue = nodeValue === 'false' ? false : nodeValue;
nodeValue = (firstChar == '{' && lastChar == '}') ||
(firstChar == '[' && lastChar == ']') ? JSON.parse(nodeValue) : nodeValue;
// Try to json parse where is possible
// 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;
} else {
model.attributes[nodeName] = nodeValue;

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

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

Loading…
Cancel
Save