Skip to content

Commit 52241a4

Browse files
authored
Merge branch 'master' into updated-oneListGroup-plus-attributes
2 parents 2360468 + 931e910 commit 52241a4

File tree

2 files changed

+21
-2
lines changed

2 files changed

+21
-2
lines changed

spec/j2x_spec.js

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -483,6 +483,19 @@ describe("XMLBuilder", function() {
483483
expect(result).toEqual(expected);
484484
});
485485

486+
it("should correctly handle values with oneListGroup", function() {
487+
const jObj = {
488+
"a": [
489+
"(first)",
490+
"(second)"
491+
],
492+
};
493+
const builder = new XMLBuilder({oneListGroup:"true", attributesGroupName: "@"});
494+
const result = builder.build(jObj);
495+
const expected = `<a>(first)(second)</a>`;
496+
expect(result).toEqual(expected);
497+
});
498+
486499
it("should handle attributes with oneListGroup", function() {
487500
const jObj = {
488501
"a": [
@@ -506,7 +519,7 @@ describe("XMLBuilder", function() {
506519
const expected = `<a foo="bar" baz="foo" bar="baz"><b>1</b><b>2</b></a>`;
507520
expect(result).toEqual(expected);
508521
});
509-
522+
510523
it('should build tag with only text node', async () => {
511524
const schema_obj = {
512525
field: {

src/xmlbuilder/json2xml.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,13 @@ Builder.prototype.j2x = function(jObj, level) {
135135
listTagVal += this.processTextOrObjNode(item, key, level)
136136
}
137137
} else {
138-
listTagVal += this.buildTextValNode(item, key, '', level);
138+
if (this.options.oneListGroup) {
139+
let textValue = this.options.tagValueProcessor(key, item);
140+
textValue = this.replaceEntitiesValue(textValue);
141+
listTagVal += textValue;
142+
} else {
143+
listTagVal += this.buildTextValNode(item, key, '', level);
144+
}
139145
}
140146
}
141147
if(this.options.oneListGroup){

0 commit comments

Comments
 (0)