Skip to content

Commit

Permalink
Encode all Ampersands
Browse files Browse the repository at this point in the history
The current regex for replacing ampersands has a flawed check to see if the ampersand is used HTML-encoded character. The regex isn't working because it ignores whitespace between the `&` and the `;` character. Also I don't think it's the responsibility of the writer to interpret if a value has been encoded already. This should fix oozcitak#110 and oozcitak#109
  • Loading branch information
coffeemakr authored Mar 28, 2022
1 parent 3f8d868 commit 04f079e
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion src/writers/BaseWriter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -928,7 +928,7 @@ export abstract class BaseWriter<T extends BaseWriterOptions, U extends XMLSeria
* 5. Replace any occurrences of ">" in markup by "&gt;".
* 6. Return the value of markup.
*/
const markup = node.data.replace(/(?!&([^&; ]*);)&/g, '&amp;')
const markup = node.data.replace(/&/g, '&amp;')
.replace(/</g, '&lt;')
.replace(/>/g, '&gt;')

Expand Down

0 comments on commit 04f079e

Please sign in to comment.