Skip to content

Commit c0a436f

Browse files
committed
prevent double convert of attributes
1 parent fd38f92 commit c0a436f

File tree

2 files changed

+5
-3
lines changed

2 files changed

+5
-3
lines changed

src/PHPHtmlParser/Dom/AbstractNode.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,8 +70,8 @@ public function __construct()
7070
public function __get($key)
7171
{
7272
// check attribute first
73-
if ( ! is_null($this->getAttribute($key))) {
74-
return $this->getAttribute($key);
73+
if ( ! is_null($value = $this->getAttribute($key))) {
74+
return $value;
7575
}
7676
switch (strtolower($key)) {
7777
case 'outerhtml':

src/PHPHtmlParser/Dom/Tag.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,7 @@ public function setAttribute($key, $value)
146146
$value = [
147147
'value' => $value,
148148
'doubleQuote' => true,
149+
'didConvertCharset' => true,
149150
];
150151
}
151152
$this->attr[$key] = $value;
@@ -217,9 +218,10 @@ public function getAttribute($key)
217218
return null;
218219
}
219220
$value = $this->attr[$key]['value'];
220-
if (is_string($value) && ! is_null($this->encode)) {
221+
if (is_string($value) && ! is_null($this->encode) && ! ($this->attr[$key]['didConvertCharset'] ?? false)) {
221222
// convert charset
222223
$this->attr[$key]['value'] = $this->encode->convert($value);
224+
$this->attr[$key]['didConvertCharset'] = true;
223225
}
224226

225227
return $this->attr[$key];

0 commit comments

Comments
 (0)