Skip to content

Commit d0a8d35

Browse files
authored
Merge pull request #184 from JanisE/master
Escape all text values for any XML element properly
2 parents 3da51c0 + c401f5e commit d0a8d35

File tree

2 files changed

+5
-9
lines changed

2 files changed

+5
-9
lines changed

lib/Redmine/Api/Issue.php

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -91,14 +91,10 @@ private function buildXML(array $params = array())
9191
$upload_item->addChild($upload_k, $upload_v);
9292
}
9393
}
94-
} elseif ('description' === $k && (strpos($v, "\n") !== false || strpos($v, PHP_EOL) !== false)) {
95-
// surround the description with CDATA if there is any '\n' in the description
96-
$node = $xml->addChild($k);
97-
$domNode = dom_import_simplexml($node);
98-
$no = $domNode->ownerDocument;
99-
$domNode->appendChild($no->createCDATASection($v));
10094
} else {
101-
$xml->addChild($k, $v);
95+
// "addChild" does not escape text for XML value, but the setter does.
96+
// http://stackoverflow.com/a/555039/99904
97+
$xml->$k = $v;
10298
}
10399
}
104100

test/Redmine/Tests/IssueXmlTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -135,8 +135,8 @@ public function testCreateComplexWithLineBreakInDescription()
135135
$xml = '<?xml version="1.0"?>
136136
<issue>
137137
<subject>test api (xml) 3</subject>
138-
<description><![CDATA[line1
139-
line2]]></description>
138+
<description>line1
139+
line2</description>
140140
<project_id>test</project_id>
141141
<assigned_to_id>1</assigned_to_id>
142142
<custom_fields type="array">

0 commit comments

Comments
 (0)