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

attribute values are corrupted when saxes runs without a text handler. #38

Closed
lddubeau opened this issue Apr 10, 2020 · 0 comments
Closed
Assignees
Labels
bug Something isn't working

Comments

@lddubeau
Copy link
Owner

This happens with 5.0.0. I have not checked older versions.

Steps to reproduce

Save this to a file:

"use strict";

/* eslint-disable no-console */

const fs = require("fs");
const saxes = require("../build/dist/saxes");

const xml = fs.readFileSync(process.argv[2]);
const parser = new saxes.SaxesParser({ xmlns: false });
parser.on("opentag", tag => {
  console.log(tag);
});
parser.on("error", err => {
  console.error(err);
});

parser.write(xml);
parser.close();

Update the path for saxes in the require call so that it loads a local version of saxes.

Save this to a file:

<?xml version="1.0" encoding="UTF-8"?>
<top>
<x>Fnord '&lt;' and then some.</x>
<x x="foo"></x>
</top>

Run node path/to/js/file path/to/xml/file with the two files above that you've saved.

Expected Result

The output should be:

{
  name: 'top',
  attributes: [Object: null prototype] {},
  isSelfClosing: false
}
{
  name: 'x',
  attributes: [Object: null prototype] {},
  isSelfClosing: false
}
{
  name: 'x',
  attributes: [Object: null prototype] { x: 'foo' },
  isSelfClosing: false
}

Namely the x attribute on the second x element should have the value foo.

Actual Output

{
  name: 'top',
  attributes: [Object: null prototype] {},
  isSelfClosing: false
}
{
  name: 'x',
  attributes: [Object: null prototype] {},
  isSelfClosing: false
}
{
  name: 'x',
  attributes: [Object: null prototype] { x: '<foo' },
  isSelfClosing: false
}

Note the less than symbol in the value of the x attribute.

Observations

The issue disappears if a handler is added for the text event.

@lddubeau lddubeau added the bug Something isn't working label Apr 10, 2020
@lddubeau lddubeau self-assigned this Apr 10, 2020
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

No branches or pull requests

1 participant