Skip to content

Commit 0a8ae3f

Browse files
committed
Sanitize attributes as well as values
1 parent 0dc7cb9 commit 0a8ae3f

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

XMLSerializer.php

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,9 @@ private static function tag_open($key, $depth = 0, $attributes = null, $self_clo
137137
echo $key;
138138
if ($attributes) {
139139
foreach ($attributes as $attribute_key => $attribute_value) {
140-
echo " {$attribute_key}=\"{$attribute_value}\"";
140+
echo " {$attribute_key}=\"";
141+
self::sanitized_scalar($attribute_value);
142+
echo "\"";
141143
}
142144
}
143145
if ($self_closing) {
@@ -149,13 +151,17 @@ private static function tag_open($key, $depth = 0, $attributes = null, $self_clo
149151

150152
private static function tag_value($value, $depth) {
151153
if (self::is_scalar($value)) {
152-
echo $value;
154+
self::sanitized_scalar($value);
153155
} else if (is_array($value)) {
154156
echo self::NEWLINE;
155157
self::_to_xml($value, $depth);
156158
}
157159
}
158160

161+
private static function sanitized_scalar($value) {
162+
echo str_replace(array('&', "'", '"'), array('&', ''', '"'), $value);
163+
}
164+
159165
private static function tag_close($key, $depth) {
160166
if ($depth > 0) {
161167
self::indent($depth);

0 commit comments

Comments
 (0)