Skip to content

Commit

Permalink
Bug where no prototypical inheritence chain exists
Browse files Browse the repository at this point in the history
- Some transpilers will create objects using `Object.create(null)`.  This creates an object with no prototypical inheritence, so no `hasOwnProperty`.

The fix is if such an object exists, we use `Object.assign` to copy the prototype from an empty object into the obj.

Signed-off-by: NoMan2000 <[email protected]>
  • Loading branch information
NoMan2000 committed May 6, 2020
1 parent 699b984 commit b4b0485
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 7 deletions.
4 changes: 4 additions & 0 deletions src/wsdl/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -730,6 +730,10 @@ export class WSDL {
}
} else if (typeof obj === 'object') {
for (name in obj) {
// Happens when Object.create(null) is used, it will not inherit the Object prototype
if (!obj.hasOwnProperty) {
obj = Object.assign({}, obj);
}
if (!obj.hasOwnProperty(name)) { continue; }
// don't process attributes as element
if (name === this.options.attributesKey) {
Expand Down
32 changes: 25 additions & 7 deletions test/wsdl-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -240,32 +240,50 @@ describe('WSDL Parser (non-strict)', () => {
});
});
});

it('should describe recursive wsdl with extended elements', (done) => {
soap.createClient(__dirname+'/wsdl/extended_recursive.wsdl', function(err, client) {
assert.ifError(err);
var desc = client.describe();
var desc = client.describe();
var personDescription = desc.Service1.BasicHttpBinding_IService1.GetPerson.output.GetPersonResult;
assert.equal(personDescription, personDescription.Department.HeadOfDepartment);
done();
});
});
});

it('should describe referenced elements with type of the same name', (done) => {
soap.createClient(__dirname+'/wsdl/ref_element_same_as_type.wsdl', function(err, client) {
assert.ifError(err);
var desc = client.describe();
var desc = client.describe();
assert.equal(desc.MyService.MyPort.MyOperation.input.ExampleContent.MyID, 'xsd:string');
done();
});
});
});

it('should describe port type', (done) => {
soap.createClient(__dirname+'/wsdl/ref_element_same_as_type.wsdl', function(err, client) {
assert.ifError(err);
var desc = client.wsdl.definitions.portTypes.MyPortType.description(client.wsdl.definitions);
var desc = client.wsdl.definitions.portTypes.MyPortType.description(client.wsdl.definitions);
assert.equal(desc.MyOperation.input.ExampleContent.MyID, 'xsd:string');
done();
});
});
});

it('Should convert objects without prototypical chains to objects with prototypical chains', function () {
var noPrototypeObj = Object.create(null);
assert.ok(typeof noPrototypeObj.hasOwnProperty === 'undefined');
noPrototypeObj.a = 'a';
noPrototypeObj.b = 'b';
const xml = fs.readFileSync(__dirname + '/wsdl/binding_document.wsdl', 'utf8');
var processed = new WSDL(xml, __dirname + '/wsdl/binding_document.wsdl', {});
processed.definitions = {
schemas: {
foo: {}
}
};
var parsed = processed.objectToXML(noPrototypeObj, 'a', 'xsd', 'foo');
assert.equal(parsed, '<a>a</a><b>b</b>');
});


});

0 comments on commit b4b0485

Please sign in to comment.