Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: escape entities in attributes #17

Merged
merged 2 commits into from
Oct 1, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ All notable changes to [tiny-svg](https://github.com/bpmn-io/tiny-svg) are docum

___Note:__ Yet to be released changes appear here._

## 4.1.3

* `FIX`: escape entities in attributes ([#16](https://github.com/bpmn-io/tiny-svg/issues/16))

## 4.1.2

* `CHORE`: make `clear` work standalone
Expand Down
2 changes: 1 addition & 1 deletion lib/util/serialize.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
*/

var TEXT_ENTITIES = /([&<>]{1})/g;
var ATTR_ENTITIES = /([\n\r"]{1})/g;
var ATTR_ENTITIES = /([&<>\n\r"]{1})/g;

var ENTITY_REPLACEMENT = {
'&': '&amp;',
Expand Down
35 changes: 35 additions & 0 deletions test/spec/innerSVG.js
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,41 @@ describe('inner-svg', function() {
expect(svg).to.eql(text);
});


it('should escape <> in attributes', function() {

// given
var container = createContainer();
var element = appendTo(create('svg'), container);

var text = '<g><rect data-foo="1 &lt; 2"/></g>';
barmac marked this conversation as resolved.
Show resolved Hide resolved

innerSVG(element, text);

// when
var svg = innerSVG(element);

// then
expect(svg).to.eql(text);
});


it('should escape & in attributes', function() {

// given
var container = createContainer();
var element = appendTo(create('svg'), container);

var text = '<g><rect data-foo="1 &amp; 2"/></g>';

innerSVG(element, text);

// when
var svg = innerSVG(element);

// then
expect(svg).to.eql(text);
});
});

});