Skip to content

Commit

Permalink
fix(write): force adding local namespace declarations
Browse files Browse the repository at this point in the history
This ensures that we always use the inner most form for namespace
declarations in cases where namespaces are declared multiple times, with
different prefixes:

```xml
<root:complexNesting xmlns:root="http://properties" id="ComplexNesting">
  <complexNesting xmlns="http://properties">
    <complexNesting>
      <foo:complexNesting xmlns:foo="http://properties" />
    </complexNesting>
  </complexNesting>
</root:complexNesting>
```

Outer, unused declarations are still cleaned up accordingly, as this is
our existing behavior.

This means that we never export something like this (because we strip
the global, unused declaration):

```xml
<root xmlns="http://extended" xmlns:unused="http://properties"
id="Root">
  <base xmlns="http://properties" />
</root>
```

Related to bpmn-io/bpmn-js#1310
  • Loading branch information
nikku authored and fake-join[bot] committed Apr 15, 2020
1 parent 911ccca commit 4879585
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/write.js
Original file line number Diff line number Diff line change
Expand Up @@ -564,7 +564,7 @@ ElementSerializer.prototype.logNamespace = function(ns, wellknown, local) {

var existing = namespaces.byUri(nsUri);

if (!existing) {
if (!existing || local) {
namespaces.add(ns, wellknown);
}

Expand Down
26 changes: 26 additions & 0 deletions test/spec/writer.js
Original file line number Diff line number Diff line change
Expand Up @@ -930,6 +930,32 @@ describe('Writer', function() {
expect(xml).to.eql('<foo:root xmlns:foo="http://properties" id="Root" />');
});


it('local namespace re-definition', function() {

// given
var writer = createWriter(extendedModel);

var root = extendedModel.create('props:Root', {
xmlns: 'http://properties',
id: 'Root',
'xmlns:ext': 'http://extended',
any: [
extendedModel.create('ext:ExtendedComplex', { xmlns: 'http://extended' })
]
});

// when
var xml = writer.toXML(root);

// then
expect(xml).to.eql(
'<root xmlns="http://properties" id="Root">' +
'<extendedComplex xmlns="http://extended" />' +
'</root>'
);
});

});


Expand Down

0 comments on commit 4879585

Please sign in to comment.