Skip to content

Commit

Permalink
Fixes #109 & #110
Browse files Browse the repository at this point in the history
  • Loading branch information
Jordan Grubb committed Nov 11, 2022
1 parent 17d2390 commit 4e494e6
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
1 change: 1 addition & 0 deletions src/constants.ts
@@ -0,0 +1 @@
export const nonEntityAmpersandRegex = /&(?![A-Za-z]+;|#\d+;)/g;
5 changes: 3 additions & 2 deletions src/writers/BaseWriter.ts
Expand Up @@ -7,6 +7,7 @@ import { LocalNameSet } from "@oozcitak/dom/lib/serializer/LocalNameSet"
import { NamespacePrefixMap } from "@oozcitak/dom/lib/serializer/NamespacePrefixMap"
import { namespace as infraNamespace } from "@oozcitak/infra"
import { xml_isName, xml_isLegalChar, xml_isPubidChar } from "@oozcitak/dom/lib/algorithm"
import { nonEntityAmpersandRegex } from "../constants"

/**
* Pre-serializes XML nodes.
Expand Down Expand Up @@ -928,7 +929,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(nonEntityAmpersandRegex, '&amp;')
.replace(/</g, '&lt;')
.replace(/>/g, '&gt;')

Expand Down Expand Up @@ -1597,7 +1598,7 @@ export abstract class BaseWriter<T extends BaseWriterOptions, U extends XMLSeria
* grammar requirement in the XML specification's AttValue production by
* also replacing ">" characters.
*/
return value.replace(/(?!&([^&; ]*);)&/g, '&amp;')
return value.replace(nonEntityAmpersandRegex, '&amp;')
.replace(/</g, '&lt;')
.replace(/>/g, '&gt;')
.replace(/"/g, '&quot;')
Expand Down

0 comments on commit 4e494e6

Please sign in to comment.