-
-
Notifications
You must be signed in to change notification settings - Fork 337
Open
Description
According to the documentation, the parser object property "tag" reflects "The current tag being dealt with."
This does not work in all cases. See the following test:
import sax from "sax";
test("parser.tag.name should be to current element in ontext", () => {
const parser = sax.parser(true);
let currentElement: string[] = []
parser.onopentag = (node) => { currentElement.push(node.name); };
parser.onclosetag = (node) => { currentElement.pop(); };
parser.ontext = (text) => {
expect(parser.tag.name + " - " + text).toBe(currentElement[currentElement.length-1]+ " - " + text);
}
parser.write('<some><sub>Text<b>bold</b></sub></some>').close();
});
This (Jest) test fails:
Error: expect(received).toBe(expected) // Object.is equality
Expected: "sub - Text"
Received: "b - Text"
IMHO this is a bug. It seems as if the parser already detects the opening tag after the text, which also means the end of the text. But this following tag must not be the tag when ontext is called. It is weird that the parser's tag contains a new tag before onopentag (or onopentagstart) has been called. It actually means that ontext is called after the parser has found a new tag -- in other words it is called too late (from a client perspective)!
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels