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

& written instead of & #110

Closed
HenkBoxma opened this issue Oct 14, 2021 · 4 comments · Fixed by #124
Closed

& written instead of & #110

HenkBoxma opened this issue Oct 14, 2021 · 4 comments · Fixed by #124
Assignees
Labels
bug Something isn't working

Comments

@HenkBoxma
Copy link

Describe the bug

When I export the following string to XML:

Hello & world today; or tomorrow

The XML that I get is:

<text>Hello & world today; or tomorrow</text>

This is invalid, because the & must be encoded as &amp;

To Reproduce
Export the string Hello & world today; or tomorrow to XML.

Expected behavior
Expected value: <text>Hello &amp; world today; or tomorrow</text

Version:

  • node.js: [14.17.4]
  • xmlbuilder2 [3.0.2]

Additional context
I suspect that the root cause is that the parser has a regular expression that assumes that all in between the & and ; are treated as an entity.
In the example above, if you'd remove the semicolon, it will export

@HenkBoxma HenkBoxma added the bug Something isn't working label Oct 14, 2021
@Laurianti
Copy link

I think it's similar issue:
#109

@HenkBoxma
Copy link
Author

Seems to be related. Note that in my example, there are .spaces between the & and the ;.

@Laurianti
Copy link

Yes, yes, I tested with your example, same problem.
I added your example to my issue.
I think this a regex issue (greedy/lazy) or similar.

coffeemakr added a commit to coffeemakr/xmlbuilder2 that referenced this issue Mar 28, 2022
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
@coffeemakr coffeemakr mentioned this issue Mar 28, 2022
4 tasks
kmasterson-nprdm pushed a commit to npr/xmlbuilder2 that referenced this issue Nov 11, 2022
@jgrubb16 jgrubb16 mentioned this issue Nov 11, 2022
4 tasks
@llamadeus
Copy link

Any news on this?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants