@@ -52,15 +52,34 @@ public function testParseMergesInheritedStylesAndKeepsAllowedTags(): void
5252 self ::assertCount (3 , $ nodes [0 ]->children );
5353 self ::assertSame ('span ' , $ nodes [0 ]->children [0 ]->tag );
5454 self ::assertSame ('Hello ' , $ nodes [0 ]->children [0 ]->children [0 ]->text );
55+ self ::assertSame ('font-size:10;font-weight:bold ' , $ nodes [0 ]->children [0 ]->attributes ['style ' ]);
5556 self ::assertSame (
56- 'font-size:10; margin:2; font-weight:bold ' ,
57+ 'font-size:10;font-weight:bold ' ,
5758 $ nodes [0 ]->children [0 ]->children [0 ]->attributes ['style ' ],
5859 );
5960 self ::assertSame ('br ' , $ nodes [0 ]->children [1 ]->tag );
6061 self ::assertSame ('World ' , $ nodes [0 ]->children [2 ]->text );
6162 self ::assertSame ('font-size:10; margin:2 ' , $ nodes [0 ]->children [2 ]->attributes ['style ' ]);
6263 }
6364
65+ public function testParseOnlyInheritsTextualStylesToDescendants (): void
66+ {
67+ $ parser = new SubsetHtmlParser ();
68+
69+ $ nodes = $ parser ->parse (
70+ '<div style="width:58%;height:100%;padding:18 24;font-size:20;color:#123456"> '
71+ . '<div style="font-weight:700">Title</div> '
72+ . '</div> ' ,
73+ );
74+
75+ self ::assertSame ('width:58%;height:100%;padding:18 24;font-size:20;color:#123456 ' , $ nodes [0 ]->attributes ['style ' ]);
76+ self ::assertSame ('font-size:20;color:#123456;font-weight:700 ' , $ nodes [0 ]->children [0 ]->attributes ['style ' ]);
77+ self ::assertSame ('font-size:20;color:#123456;font-weight:700 ' , $ nodes [0 ]->children [0 ]->children [0 ]->attributes ['style ' ]);
78+ self ::assertStringNotContainsString ('width:58% ' , $ nodes [0 ]->children [0 ]->attributes ['style ' ]);
79+ self ::assertStringNotContainsString ('height:100% ' , $ nodes [0 ]->children [0 ]->attributes ['style ' ]);
80+ self ::assertStringNotContainsString ('padding:18 24 ' , $ nodes [0 ]->children [0 ]->attributes ['style ' ]);
81+ }
82+
6483 public function testParseNormalizesTagAndAttributeNamesAndKeepsAllAttributes (): void
6584 {
6685 $ parser = new SubsetHtmlParser ();
0 commit comments