-
Notifications
You must be signed in to change notification settings - Fork 712
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix rendering of exported SVG (#2794)
Replace invalid characters in attribute value; fixes the error Unescaped '<' not allowed in attributes values Fixes #2534
- Loading branch information
Showing
4 changed files
with
37 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import { encodeIdAttribute, decodeIdAttribute } from '../dom-utils'; | ||
|
||
describe('DomUtils', () => { | ||
describe('encodeIdAttribute/decodeIdAttribute', () => { | ||
it('encode should be reversible by decode ', () => { | ||
[ | ||
'123-abc;<foo>', | ||
';;<<><>', | ||
'!@#$%^&*()+-\'"', | ||
].forEach((input) => { | ||
expect(decodeIdAttribute(encodeIdAttribute(input))).toEqual(input); | ||
}); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
/** | ||
* Cleans up a value to be used as an element ID. | ||
* | ||
* Encodes invalid characters to be valid in XHTML and makes it | ||
* so that it can be reversed by {@link decodeIdAttribute}. | ||
*/ | ||
export function encodeIdAttribute(id) { | ||
return id.replace(/[<>&;]/gm, m => `__u${m.charCodeAt(0)}__`); | ||
} | ||
|
||
/** | ||
* Reverts {@link encodeIdAttribute}. | ||
*/ | ||
export function decodeIdAttribute(id) { | ||
return id.replace(/__u(\d+)__/gm, (m, d) => String.fromCharCode(d)); | ||
} |