File tree 4 files changed +52
-1
lines changed 4 files changed +52
-1
lines changed Original file line number Diff line number Diff line change @@ -255,6 +255,10 @@ private function parseStringValue() {
255
255
256
256
private function parseCharacter ($ bIsForIdentifier ) {
257
257
if ($ this ->peek () === '\\' ) {
258
+ if ($ bIsForIdentifier && $ this ->oParserSettings ->bLenientParsing && ($ this ->comes ('\0 ' ) || $ this ->comes ('\9 ' ))) {
259
+ // Non-strings can contain \0 or \9 which is an IE hack supported in lenient parsing.
260
+ return null ;
261
+ }
258
262
$ this ->consume ('\\' );
259
263
if ($ this ->comes ('\n ' ) || $ this ->comes ('\r ' )) {
260
264
return '' ;
@@ -350,6 +354,13 @@ private function parseRule() {
350
354
$ this ->consume (': ' );
351
355
$ oValue = $ this ->parseValue (self ::listDelimiterForRule ($ oRule ->getRule ()));
352
356
$ oRule ->setValue ($ oValue );
357
+ if ($ this ->oParserSettings ->bLenientParsing ) {
358
+ while ($ this ->comes ('\\' )) {
359
+ $ this ->consume ('\\' );
360
+ $ oRule ->addIeHack ($ this ->consume ());
361
+ $ this ->consumeWhiteSpace ();
362
+ }
363
+ }
353
364
if ($ this ->comes ('! ' )) {
354
365
$ this ->consume ('! ' );
355
366
$ this ->consumeWhiteSpace ();
@@ -367,7 +378,7 @@ private function parseValue($aListDelimiters) {
367
378
$ aStack = array ();
368
379
$ this ->consumeWhiteSpace ();
369
380
//Build a list of delimiters and parsed values
370
- while (!($ this ->comes ('} ' ) || $ this ->comes ('; ' ) || $ this ->comes ('! ' ) || $ this ->comes (') ' ))) {
381
+ while (!($ this ->comes ('} ' ) || $ this ->comes ('; ' ) || $ this ->comes ('! ' ) || $ this ->comes (') ' ) || $ this -> comes ( '\\' ) )) {
371
382
if (count ($ aStack ) > 0 ) {
372
383
$ bFoundDelimiter = false ;
373
384
foreach ($ aListDelimiters as $ sDelimiter ) {
Original file line number Diff line number Diff line change @@ -15,12 +15,14 @@ class Rule implements Renderable {
15
15
private $ sRule ;
16
16
private $ mValue ;
17
17
private $ bIsImportant ;
18
+ private $ aIeHack ;
18
19
protected $ iLineNo ;
19
20
20
21
public function __construct ($ sRule , $ iLineNo = 0 ) {
21
22
$ this ->sRule = $ sRule ;
22
23
$ this ->mValue = null ;
23
24
$ this ->bIsImportant = false ;
25
+ $ this ->aIeHack = array ();
24
26
$ this ->iLineNo = $ iLineNo ;
25
27
}
26
28
@@ -127,6 +129,18 @@ public function addValue($mValue, $sType = ' ') {
127
129
}
128
130
}
129
131
132
+ public function addIeHack ($ iModifier ) {
133
+ $ this ->aIeHack [] = $ iModifier ;
134
+ }
135
+
136
+ public function setIeHack (array $ aModifiers ) {
137
+ $ this ->aIeHack = $ aModifiers ;
138
+ }
139
+
140
+ public function getIeHack () {
141
+ return $ this ->aIeHack ;
142
+ }
143
+
130
144
public function setIsImportant ($ bIsImportant ) {
131
145
$ this ->bIsImportant = $ bIsImportant ;
132
146
}
@@ -146,6 +160,9 @@ public function render(\Sabberworm\CSS\OutputFormat $oOutputFormat) {
146
160
} else {
147
161
$ sResult .= $ this ->mValue ;
148
162
}
163
+ if (!empty ($ this ->aIeHack )) {
164
+ $ sResult .= ' \\' . implode ('\\' , $ this ->aIeHack );
165
+ }
149
166
if ($ this ->bIsImportant ) {
150
167
$ sResult .= ' !important ' ;
151
168
}
Original file line number Diff line number Diff line change @@ -505,4 +505,18 @@ function testUnexpectedTokenExceptionLineNo() {
505
505
throw $ e ;
506
506
}
507
507
}
508
+
509
+ /**
510
+ * @expectedException Sabberworm\CSS\Parsing\UnexpectedTokenException
511
+ */
512
+ function testIeHacksStrictParsing () {
513
+ // We can't strictly parse IE hacks.
514
+ $ this ->parsedStructureForFile ('ie-hacks ' , Settings::create ()->beStrict ());
515
+ }
516
+
517
+ function testIeHacksParsing () {
518
+ $ oDoc = $ this ->parsedStructureForFile ('ie-hacks ' , Settings::create ()->withLenientParsing (true ));
519
+ $ sExpected = 'p {padding-right: .75rem \9;background-image: none \9;color: red \9\0;background-color: red \9\0;background-color: red \9\0 !important;content: "red \0";content: "red઼";} ' ;
520
+ $ this ->assertEquals ($ sExpected , $ oDoc ->render ());
521
+ }
508
522
}
Original file line number Diff line number Diff line change
1
+ p {
2
+ padding-right : .75rem \9;
3
+ background-image : none \9;
4
+ color : red\9\0;
5
+ background-color : red \9 \0;
6
+ background-color : red \9 \0 !important ;
7
+ content : "red \9\0" ;
8
+ content : "red\0abc" ;
9
+ }
You can’t perform that action at this time.
0 commit comments