Skip to content

Commit

Permalink
Correctly handling empty namespaces xmlns="".
Browse files Browse the repository at this point in the history
Fixes #40
  • Loading branch information
evert committed Mar 19, 2015
1 parent f599524 commit 1b5df36
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 6 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
ChangeLog
=========

0.4.1 (2015-03-19)
-----------------

* #40: An element with an empty namespace (xmlns="") is not allowed to have a
prefix. This is now fixed.


0.4.0 (2015-03-18)
------------------

Expand Down
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
"bin" : [
],
"require-dev": {
"squizlabs/php_codesniffer": "*"
"squizlabs/php_codesniffer": "*",
"phpunit/phpunit" : "*"
}
}
2 changes: 1 addition & 1 deletion lib/Version.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,6 @@ class Version {
/**
* Full version number
*/
const VERSION = '0.4.0';
const VERSION = '0.4.1';

}
13 changes: 10 additions & 3 deletions lib/Writer.php
Original file line number Diff line number Diff line change
Expand Up @@ -166,10 +166,17 @@ function startElement($name) {
$result = $this->startElementNS($this->namespaceMap[$namespace], $localName, null);
} else {

if (!isset($this->adhocNamespaces[$namespace])) {
$this->adhocNamespaces[$namespace] = 'x' . (count($this->adhocNamespaces)+1);
// An empty namespace means it's the global namespace. This is
// allowed, but it mustn't get a prefix.
if ($namespace==="") {
$result = $this->startElement($localName);
$this->writeAttribute('xmlns', '');
} else {
if (!isset($this->adhocNamespaces[$namespace])) {
$this->adhocNamespaces[$namespace] = 'x' . (count($this->adhocNamespaces)+1);
}
$result = $this->startElementNS($this->adhocNamespaces[$namespace], $localName, $namespace);
}
$result = $this->startElementNS($this->adhocNamespaces[$namespace], $localName, $namespace);
}

} else {
Expand Down
2 changes: 1 addition & 1 deletion tests/Sabre/XML/WriterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ function testEmptyNamespace() {
], <<<HI
<?xml version="1.0"?>
<s:root xmlns:s="http://sabredav.org/ns">
<x1:elem1 xmlns:x1="">bar</x1:elem1>
<elem1 xmlns="">bar</elem1>
</s:root>
HI
Expand Down

0 comments on commit 1b5df36

Please sign in to comment.