Skip to content

Commit e534a50

Browse files
authored
Merge pull request #259 from Art4/233-patch-xml-element-error
Handle xml entities in projects, wiki and issue api
2 parents 8a3dc92 + fde0bd0 commit e534a50

File tree

6 files changed

+17
-12
lines changed

6 files changed

+17
-12
lines changed

src/Redmine/Api/Project.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ protected function prepareParamsXml($params)
171171
$array->addChild($_params[$k], $id);
172172
}
173173
} else {
174-
$xml->addChild($k, $v);
174+
$xml->addChild($k, htmlspecialchars($v));
175175
}
176176
}
177177

src/Redmine/Api/Wiki.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ public function create($project, $page, array $params = [])
8181
}
8282
}
8383
} else {
84-
$xml->addChild($k, $v);
84+
$xml->addChild($k, htmlspecialchars($v));
8585
}
8686
}
8787

tests/Unit/Api/IssueTest.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -842,7 +842,8 @@ public function testBuildXmlWithWatcherAndUploadAndCustomFieldAndStandard()
842842
// Test values
843843
$parameters = [
844844
'watcher_user_ids' => [5],
845-
'subject' => 'Issue subject',
845+
'subject' => 'Issue subject with some xml entities: & < > " \' ',
846+
'description' => 'Description with some xml entities: & < > " \' ',
846847
'uploads' => [
847848
[
848849
'token' => 'first-token',
@@ -883,7 +884,8 @@ public function testBuildXmlWithWatcherAndUploadAndCustomFieldAndStandard()
883884
.'<value>Second Custom Field</value>'
884885
.'</custom_field>'
885886
),
886-
$this->stringContains('<subject>Issue subject</subject>')
887+
$this->stringContains('<subject>Issue subject with some xml entities: &amp; &lt; &gt; " \' </subject>'),
888+
$this->stringContains('<description>Description with some xml entities: &amp; &lt; &gt; " \' </description>')
887889
)
888890
);
889891

tests/Unit/Api/ProjectTest.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -410,7 +410,8 @@ public function testCreateCallsPost()
410410
$getResponse = 'API Response';
411411
$parameters = [
412412
'identifier' => 'test-project',
413-
'name' => 'Test Project',
413+
'name' => 'Test Project with some xml entities: & < > " \' ',
414+
'description' => 'Description with some xml entities: & < > " \' ',
414415
];
415416

416417
// Create the used mock objects
@@ -425,7 +426,8 @@ public function testCreateCallsPost()
425426
$this->stringStartsWith('<?xml version="1.0"?>'."\n".'<project>'),
426427
$this->stringEndsWith('</project>'."\n"),
427428
$this->stringContains('<identifier>test-project</identifier>'),
428-
$this->stringContains('<name>Test Project</name>')
429+
$this->stringContains('<name>Test Project with some xml entities: &amp; &lt; &gt; " \' </name>'),
430+
$this->stringContains('<description>Description with some xml entities: &amp; &lt; &gt; " \' </description>')
429431
)
430432
)
431433
->willReturn($getResponse);

tests/Unit/Api/TimeEntryTest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -261,6 +261,7 @@ public function testCreateCallsPost()
261261
$this->stringContains('<issue_id>15</issue_id>'),
262262
$this->stringContains('<project_id>25</project_id>'),
263263
$this->stringContains('<hours>5.25</hours>'),
264+
$this->stringContains('<comments>some text with xml entities: &amp; &lt; &gt; " \' </comments>'),
264265
$this->stringContains('<custom_fields type="array"><custom_field name="Affected version" id="1"><value>1.0.1</value></custom_field><custom_field name="Resolution" id="2"><value>Fixed</value></custom_field></custom_fields>')
265266
)
266267
)

tests/Unit/Api/WikiTest.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -259,9 +259,9 @@ public function testCreateWithParametersCallsPost()
259259
// Test values
260260
$getResponse = 'API Response';
261261
$parameters = [
262-
'title' => 'Test Wikipage',
263-
'comments' => 'Initial Edit',
264-
'text' => 'Some page text',
262+
'title' => 'Test Wikipage with xml entities: & < > " \' ',
263+
'comments' => 'Initial Edit with xml entities: & < > " \' ',
264+
'text' => 'Some page text with xml entities: & < > " \' ',
265265
];
266266

267267
// Create the used mock objects
@@ -275,9 +275,9 @@ public function testCreateWithParametersCallsPost()
275275
$this->logicalAnd(
276276
$this->stringStartsWith('<?xml version="1.0"?>'."\n".'<wiki_page>'),
277277
$this->stringEndsWith('</wiki_page>'."\n"),
278-
$this->stringContains('<title>Test Wikipage</title>'),
279-
$this->stringContains('<comments>Initial Edit</comments>'),
280-
$this->stringContains('<text>Some page text</text>')
278+
$this->stringContains('<title>Test Wikipage with xml entities: &amp; &lt; &gt; " \' </title>'),
279+
$this->stringContains('<comments>Initial Edit with xml entities: &amp; &lt; &gt; " \' </comments>'),
280+
$this->stringContains('<text>Some page text with xml entities: &amp; &lt; &gt; " \' </text>')
281281
)
282282
)
283283
->willReturn($getResponse);

0 commit comments

Comments
 (0)