Skip to content

Commit b433e09

Browse files
committed
#1: encode double quotes to ensure the attribute is correct xml when printed
1 parent c6786da commit b433e09

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

src/Node/Attribute.php

+5-1
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,10 @@ public function __toString(): string
2727
{
2828
$name = ($this->prefix ? $this->prefix . ':' : '') . $this->localName;
2929

30-
return sprintf('%s="%s"', $name, htmlentities($this->value, ENT_XML1 | ENT_SUBSTITUTE, 'UTF-8', false));
30+
return sprintf(
31+
'%s="%s"',
32+
$name,
33+
htmlentities($this->value, ENT_XML1 | ENT_SUBSTITUTE | ENT_COMPAT, 'UTF-8', false)
34+
);
3135
}
3236
}

tests/Node/AttributeTest.php

+6
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,12 @@ public function provideAttribute(): iterable
4141
'foo',
4242
'ns1:foo="bar"'
4343
],
44+
'attribute with quote' => [
45+
new Attribute('foo', 'bar"'),
46+
'',
47+
'foo',
48+
'foo="bar""'
49+
],
4450
];
4551
}
4652
}

0 commit comments

Comments
 (0)