Skip to content

Commit

Permalink
Merge branch 'master' into updated-oneListGroup-plus-attributes
Browse files Browse the repository at this point in the history
  • Loading branch information
a-rasin authored Jul 9, 2024
2 parents 2360468 + 931e910 commit 52241a4
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
15 changes: 14 additions & 1 deletion spec/j2x_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -483,6 +483,19 @@ describe("XMLBuilder", function() {
expect(result).toEqual(expected);
});

it("should correctly handle values with oneListGroup", function() {
const jObj = {
"a": [
"(first)",
"(second)"
],
};
const builder = new XMLBuilder({oneListGroup:"true", attributesGroupName: "@"});
const result = builder.build(jObj);
const expected = `<a>(first)(second)</a>`;
expect(result).toEqual(expected);
});

it("should handle attributes with oneListGroup", function() {
const jObj = {
"a": [
Expand All @@ -506,7 +519,7 @@ describe("XMLBuilder", function() {
const expected = `<a foo="bar" baz="foo" bar="baz"><b>1</b><b>2</b></a>`;
expect(result).toEqual(expected);
});

it('should build tag with only text node', async () => {
const schema_obj = {
field: {
Expand Down
8 changes: 7 additions & 1 deletion src/xmlbuilder/json2xml.js
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,13 @@ Builder.prototype.j2x = function(jObj, level) {
listTagVal += this.processTextOrObjNode(item, key, level)
}
} else {
listTagVal += this.buildTextValNode(item, key, '', level);
if (this.options.oneListGroup) {
let textValue = this.options.tagValueProcessor(key, item);
textValue = this.replaceEntitiesValue(textValue);
listTagVal += textValue;
} else {
listTagVal += this.buildTextValNode(item, key, '', level);
}
}
}
if(this.options.oneListGroup){
Expand Down

0 comments on commit 52241a4

Please sign in to comment.