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 noDoubleEncoding with undefined XML entities #17

Merged
merged 1 commit into from
Apr 8, 2020
Merged

Fix noDoubleEncoding with undefined XML entities #17

merged 1 commit into from
Apr 8, 2020

Conversation

leafac
Copy link
Contributor

@leafac leafac commented Apr 8, 2020

Fixes #16

The \S+ in the regular expression has two problems:

  1. It’s greedy, so it matches something like &notanentity< and prevents the first & from being encoded.

  2. It allows any entity to pass through unencoded, but XML only recognizes a few entities.

The solution here is to not double encode only the few entities recognized by XML. This results in things like   being encoded into  , which seems to be what we want.

You may want to backport this fix to xmlbuilder.

Fixes #16

The \S+ in the regular expression has two problems:

1. It’s greedy, so it matches something like `&notanentity<` and prevents the first `&` from being encoded.

2. It allows **any** entity to pass through unencoded, but XML only recognizes [a few](https://www.w3.org/TR/REC-xml/#sec-predefined-ent) entities.

The solution here to not double encode only the few entities recognized by XML. This results in things like ` ` being encoded into ` `, which [seems to be what we want](https://validator.w3.org/feed/docs/error/UndefinedNamedEntity.html).

You may want to backport this fix to xmlbuilder.
@codecov-io
Copy link

codecov-io commented Apr 8, 2020

Codecov Report

Merging #17 into master will not change coverage by %.
The diff coverage is 100.00%.

Impacted file tree graph

@@           Coverage Diff           @@
##           master      #17   +/-   ##
=======================================
  Coverage   99.19%   99.19%           
=======================================
  Files          15       15           
  Lines        1874     1874           
  Branches      506      506           
=======================================
  Hits         1859     1859           
  Misses         15       15           
Impacted Files Coverage Δ
src/builder/XMLBuilderCBImpl.ts 98.70% <100.00%> (ø)
src/writers/BaseWriter.ts 97.46% <100.00%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update b4e0281...965fda7. Read the comment docs.

@oozcitak
Copy link
Owner

oozcitak commented Apr 8, 2020

Great PR! Thank you.

@oozcitak oozcitak merged commit b86ced3 into oozcitak:master Apr 8, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Named entities produce invalid XML
3 participants