Skip to content

Commit

Permalink
Merge pull request GrapesJS#939 from ryandeba/escape-attributes
Browse files Browse the repository at this point in the history
 escpae quotes in Component.toHTML
  • Loading branch information
artf authored Mar 10, 2018
2 parents e6395e2 + ff15c34 commit a36ddc9
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/dom_components/model/Component.js
Original file line number Diff line number Diff line change
Expand Up @@ -670,7 +670,7 @@ const Component = Backbone.Model.extend(Styleable).extend(
const attributes = this.getAttrToHTML();

for (let attr in attributes) {
const value = attributes[attr];
const value = attributes[attr].replace(/"/g, '"');

if (!isUndefined(value)) {
attrs.push(`${attr}="${value}"`);
Expand Down
10 changes: 10 additions & 0 deletions test/specs/dom_components/model/Component.js
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,16 @@ module.exports = {
expect(obj.toHTML()).toEqual('<div/>');
});

it('Component toHTML with quotes in attribute', () => {
obj = new Component();
let attrs = obj.get('attributes');
attrs['data-test'] = '"value"';
obj.set('attributes', attrs);
expect(obj.toHTML()).toEqual(
'<div data-test="&quot;value&quot;"></div>'
);
});

it('Component parse empty div', () => {
var el = document.createElement('div');
obj = Component.isComponent(el);
Expand Down

0 comments on commit a36ddc9

Please sign in to comment.