Skip to content

Commit

Permalink
Parse array/objects inside attributes safely
Browse files Browse the repository at this point in the history
  • Loading branch information
artf committed Oct 17, 2017
1 parent 73f4183 commit 0efe3b2
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 6 deletions.
4 changes: 2 additions & 2 deletions dist/grapes.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
9 changes: 7 additions & 2 deletions src/parser/model/ParserHtml.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion test/specs/parser/model/ParserHtml.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ const DomComponents = require('dom_components');
module.exports = {
run() {

describe.only('ParserHtml', () => {
describe('ParserHtml', () => {
var obj;

beforeEach(() => {
Expand Down

0 comments on commit 0efe3b2

Please sign in to comment.