You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Describe the bug
XMLBuilder and XMLBuilderCB handle text elements differently. By default XMLBuilder emits this:
<value>text</value>
whereas XMLBuilderCB emits:
<value>
text
</value>
XMLBuilder includes an indentTextOnlyNodes option that can be used to control the behavior but XMLBuilderCB does not.
To Reproduce
jest test:
import "jest";
import * as xb2 from "xmlbuilder2";
test("xml text bug", () => {
const b1 = xb2.create();
b1.dec({}).ele("root").ele("value").txt("frobozz").up();
let xml = b1.end({ prettyPrint: true });
expect(xml).toBe(
`<?xml version="1.0"?>\n` +
`<root>\n` +
` <value>frobozz</value>\n` +
`</root>`
);
xml = b1.end({ prettyPrint: true, indentTextOnlyNodes: true });
expect(xml).toBe(
`<?xml version="1.0"?>\n` +
`<root>\n` +
` <value>\n` +
` frobozz\n` +
` </value>\n` +
`</root>`
);
xml = "";
const b2 = xb2.createCB({
data: (chunk: string) => xml += chunk,
prettyPrint: true,
});
b2.dec({}).ele("root").ele("value").txt("frobozz").up().up();
// Expecting that this should match the first expectation above, but instead it matches the second.
// Worse createCB options does not have an indentTextOnlyNodes that can be used to alter the behavior.
expect(xml).toBe(
`<?xml version="1.0"?>\n` +
`<root>\n` +
` <value>\n` +
` frobozz\n` +
` </value>\n` +
`</root>`
);
});
Expected behavior
Expecting that both XMLBuilder and XMLBuilderDB emit identical elements by default, and that both would let you alter the behavior using indentTextOnlyNodes .
Version:
node.js: [14.15.4]
xmlbuilder2 [2.4.1]
The text was updated successfully, but these errors were encountered:
I was going to open an issue regarding not being able to pretty print when using createCB and writing in chunks. Am I right to assume whatever fixes this will fix both issues ?
Describe the bug
XMLBuilder and XMLBuilderCB handle text elements differently. By default XMLBuilder emits this:
<value>text</value>
whereas XMLBuilderCB emits:
XMLBuilder includes an indentTextOnlyNodes option that can be used to control the behavior but XMLBuilderCB does not.
To Reproduce
jest test:
import "jest";
import * as xb2 from "xmlbuilder2";
Expected behavior
Expecting that both XMLBuilder and XMLBuilderDB emit identical elements by default, and that both would let you alter the behavior using indentTextOnlyNodes .
Version:
The text was updated successfully, but these errors were encountered: