File tree Expand file tree Collapse file tree 2 files changed +24
-2
lines changed Expand file tree Collapse file tree 2 files changed +24
-2
lines changed Original file line number Diff line number Diff line change 6
6
7
7
class Loader
8
8
{
9
+ private $ entities ;
10
+
11
+ public function __construct (array $ entities = null )
12
+ {
13
+ if ($ entities === null ) {
14
+ // get all HTML entities (minus those for XML parsing)
15
+ $ entities = get_html_translation_table (HTML_ENTITIES , ENT_NOQUOTES , 'UTF-8 ' );
16
+ unset($ entities ['< ' ], $ entities ['> ' ], $ entities ['& ' ]);
17
+ }
18
+
19
+ $ this ->entities = $ entities ;
20
+ }
21
+
9
22
public function loadXmlFile ($ path )
10
23
{
11
24
return $ this ->loadXmlString (file_get_contents ($ path ));
@@ -16,8 +29,8 @@ public function loadXmlString($html)
16
29
// fix invalid markup of help link in footer of outdated ViewVC versions
17
30
$ html = str_replace ('Help</strong></td> ' , 'Help</a></strong></td> ' , $ html );
18
31
19
- // replace unneeded HTML entities
20
- $ html = str_replace (' ' , ' ' , $ html );
32
+ // replace named HTML entities with their UTF-8 value
33
+ $ html = str_replace (array_values ( $ this -> entities ), array_keys ( $ this -> entities ) , $ html );
21
34
22
35
// clean up namespace declaration
23
36
$ html = str_replace ('xmlns=" ' , 'ns=" ' , $ html );
Original file line number Diff line number Diff line change @@ -29,4 +29,13 @@ function ($path) {
29
29
scandir (__DIR__ . '/../fixtures/ ' )
30
30
));
31
31
}
32
+
33
+ public function testHtmlEntities ()
34
+ {
35
+ $ str = '<p>ä… ©</p> ' ;
36
+ $ xml = $ this ->loader ->loadXmlString ($ str );
37
+
38
+ // c3 a4 e2 80 a6 c2 a0 c2 a9
39
+ $ this ->assertEquals ('ä… © ' , (string )$ xml );
40
+ }
32
41
}
You can’t perform that action at this time.
0 commit comments