Skip to content

Commit

Permalink
Changes as suggested in the code review
Browse files Browse the repository at this point in the history
  • Loading branch information
oliverklee committed Oct 27, 2024
1 parent 3fcec5f commit 101c2c8
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 49 deletions.
2 changes: 1 addition & 1 deletion src/Css/CssDocument.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public function __construct(string $css, bool $debug)
private function hasNestedAtRule(string $css): bool
{
return (new Preg())
->match('/@(?:media|supports|(?:-webkit-|-moz-|-ms-|-o-)?+(keyframes|document))\\b/', $css) !== 0;
->match('/@(?:media|supports|(?:-webkit-|-moz-|-ms-|-o-)?+(keyframes|document))\\b/', $css) !== 0;
}

/**
Expand Down
16 changes: 8 additions & 8 deletions tests/Support/Traits/CssDataProviders.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,19 +29,19 @@ public function provideEquivalentCompleteCss(): array
{
$datasetsWithAtMediaRuleSelectorListAndPropertyDeclaration = self::crossDatasetWithItself([
'unminified CSS with `@media` rule, selector list, and property declaration'
=> ['@media screen { html, body { color: green; } }'],
=> ['@media screen { html, body { color: green; } }'],
'minified CSS with `@media` rule, selector list, and property declaration'
=> ['@media screen{html,body{color:green}}'],
=> ['@media screen{html,body{color:green}}'],
'CSS with `@media` rule, selector list, and property declaration, with extra spaces'
=> [' @media screen { html , body { color : green ; } } '],
=> [' @media screen { html , body { color : green ; } } '],
'CSS with `@media` rule, selector list, and property declaration, with linefeeds'
=> ["\n@media\nscreen\n{\nhtml\n,\nbody\n{\ncolor\n:\ngreen\n;\n}\n}\n"],
=> ["\n@media\nscreen\n{\nhtml\n,\nbody\n{\ncolor\n:\ngreen\n;\n}\n}\n"],
'CSS with `@media` rule, selector list, and property declaration, with Windows line endings'
=> ["\r\n@media\r\nscreen\r\n{\r\nhtml\r\n,\r\nbody\r\n{\r\ncolor\r\n:\r\ngreen\r\n;\r\n}\r\n}\r\n"],
=> ["\r\n@media\r\nscreen\r\n{\r\nhtml\r\n,\r\nbody\r\n{\r\ncolor\r\n:\r\ngreen\r\n;\r\n}\r\n}\r\n"],
'CSS with `@media` rule, selector list, and property declaration, with uppercase at-rule name'
=> ['@MEDIA screen { html, body { color: green; } }'],
=> ['@MEDIA screen { html, body { color: green; } }'],
'CSS with `@media` rule, selector list, and property declaration, with mixed-case at-rule name'
=> ['@MeDiA screen { html, body { color: green; } }'],
=> ['@MeDiA screen { html, body { color: green; } }'],
]);

$datasetsWithUrlPropertyValue = self::crossDatasetWithItself([
Expand All @@ -53,7 +53,7 @@ public function provideEquivalentCompleteCss(): array
'CSS with single-quoted string in property value' => ['.new::before { content: \'New Entry! \'; }'],
'CSS with double-quoted string in property value' => ['.new::before { content: "New Entry! "; }'],
'CSS with quoted string in property value without trailing semicolon'
=> ['.new::before { content: "New Entry! " }'],
=> ['.new::before { content: "New Entry! " }'],
'minified CSS with quoted string in property value' => ['.new::before{content:"New Entry! "}'],
]);

Expand Down
12 changes: 6 additions & 6 deletions tests/Unit/Css/CssDocumentTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -572,16 +572,16 @@ public function provideInvalidNonConditionalAtRuleWhichDoesNotCauseException():
return [
'`@font-face` without `font-family`' => [
'
@font-face {
src: url("/foo-sans.woff2") format("woff2");
}
@font-face {
src: url("/foo-sans.woff2") format("woff2");
}
',
],
'`@font-face` without `src`' => [
'
@font-face {
font-family: "Foo Sans";
}
@font-face {
font-family: "Foo Sans";
}
',
],
'`@import` after style rule' => ['@import "foo.css";', 'p { color: red; }'],
Expand Down
68 changes: 34 additions & 34 deletions tests/Unit/HtmlProcessor/AbstractHtmlProcessorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -224,9 +224,9 @@ public function provideHtmlWithOptionalTagsOmitted(): array
// broken: OPTGROUP end tag omission with OPTGROUP element following
'OPTGROUP end tag omission at end of list' => [
'<select><optgroup><option> 1 </option><option> 2 </option></optgroup>'
. '<optgroup><option> A </option><option> B </option></select>',
. '<optgroup><option> A </option><option> B </option></select>',
'<select><optgroup><option> 1 </option><option> 2 </option></optgroup>'
. '<optgroup><option> A </option><option> B </option></optgroup></select>',
. '<optgroup><option> A </option><option> B </option></optgroup></select>',
],
'OPTION end tag omission with OPTION element following' => [
'<select><option> 1 <option> 2 </option></select>',
Expand Down Expand Up @@ -432,9 +432,9 @@ public function provideContentWithoutHtmlTag(): array
'BODY element with Content-Type in text' => ['<body>Content-Type</body>'],
'body content only with Content-Type in text' => ['<p>Content-Type</p>'],
'BODY element containing Content-Type META tag'
=> ['<body><meta http-equiv="Content-Type" content="text/html; charset=utf-8"></body>'],
=> ['<body><meta http-equiv="Content-Type" content="text/html; charset=utf-8"></body>'],
'body content only with Content-Type META tag'
=> ['<p>hello</p><meta http-equiv="Content-Type" content="text/html; charset=utf-8">'],
=> ['<p>hello</p><meta http-equiv="Content-Type" content="text/html; charset=utf-8">'],
];
}

Expand Down Expand Up @@ -535,22 +535,22 @@ public function provideContentWithoutHeadTag(): array
'BODY element' => ['<body></body>'],
'HEADER element' => ['<header></header>'],
'http-equiv META element (implicit HEAD)'
=> ['<meta http-equiv="Content-Type" content="text/html; charset=utf-8">'],
=> ['<meta http-equiv="Content-Type" content="text/html; charset=utf-8">'],
'viewport META element (implicit HEAD)'
=> ['<meta name="viewport" content="width=device-width, initial-scale=1.0">'],
=> ['<meta name="viewport" content="width=device-width, initial-scale=1.0">'],
'META element with Content-Type as a value' => ['<meta name="description" content="Content-Type">'],
'BODY element with Content-Type in text' => ['<body>Content-Type</body>'],
'body content only with Content-Type in text' => ['<p>Content-Type</p>'],
'http-equiv META element within BODY (not allowed)'
=> ['<body><meta http-equiv="Content-Type" content="text/html; charset=utf-8"></body>'],
=> ['<body><meta http-equiv="Content-Type" content="text/html; charset=utf-8"></body>'],
'http-equiv META element after P (implicit BODY, not allowed)'
=> ['<p>hello</p><meta http-equiv="Content-Type" content="text/html; charset=utf-8">'],
=> ['<p>hello</p><meta http-equiv="Content-Type" content="text/html; charset=utf-8">'],
'http-equiv META element within P (not allowed)'
=> ['<p><meta http-equiv="Content-Type" content="text/html; charset=utf-8"></p>'],
=> ['<p><meta http-equiv="Content-Type" content="text/html; charset=utf-8"></p>'],
'viewport META element within P (allowed)'
=> ['<p><meta name="viewport" content="width=device-width, initial-scale=1.0"></p>'],
=> ['<p><meta name="viewport" content="width=device-width, initial-scale=1.0"></p>'],
'http-equiv META element within HEADER (not allowed)'
=> ['<header><meta http-equiv="Content-Type" content="text/html; charset=utf-8"></header>'],
=> ['<header><meta http-equiv="Content-Type" content="text/html; charset=utf-8"></header>'],
];
}

Expand Down Expand Up @@ -585,21 +585,21 @@ public function provideContentWithHeadTag(): array
'HEAD element and HEADER element' => ['<head></head><header></header>'],
'HEAD element with Content-Type in comment' => ['<head><!-- Content-Type --></head>'],
'HEAD element with Content-Type as META value'
=> ['<head><meta name="description" content="Content-Type"></head>'],
=> ['<head><meta name="description" content="Content-Type"></head>'],
'with BODY element with Content-Type in text' => ['<head></head><body>Content-Type</body>'],
'with implicit body content with Content-Type in text' => ['<head></head><p>Content-Type</p>'],
'with BODY element containing Content-Type META tag'
=> ['<head></head><body><meta http-equiv="Content-Type" content="text/html; charset=utf-8"></body>'],
=> ['<head></head><body><meta http-equiv="Content-Type" content="text/html; charset=utf-8"></body>'],
'with implicit body content with Content-Type META tag'
=> ['<head></head><p>hello</p><meta http-equiv="Content-Type" content="text/html; charset=utf-8">'],
=> ['<head></head><p>hello</p><meta http-equiv="Content-Type" content="text/html; charset=utf-8">'],
'with end tag omitted and BODY element containing Content-Type META tag'
=> ['<head><body><meta http-equiv="Content-Type" content="text/html; charset=utf-8"></body>'],
=> ['<head><body><meta http-equiv="Content-Type" content="text/html; charset=utf-8"></body>'],
'with end tag omitted and implicit body content with Content-Type META tag'
=> ['<head><p>hello</p><meta http-equiv="Content-Type" content="text/html; charset=utf-8">'],
=> ['<head><p>hello</p><meta http-equiv="Content-Type" content="text/html; charset=utf-8">'],
'with Content-Type META tag after end tag'
=> ['<head></head><meta http-equiv="Content-Type" content="text/html; charset=utf-8">'],
=> ['<head></head><meta http-equiv="Content-Type" content="text/html; charset=utf-8">'],
'with Content-Type META tag after uppercase end tag'
=> ['<HEAD></HEAD><meta http-equiv="Content-Type" content="text/html; charset=utf-8">'],
=> ['<HEAD></HEAD><meta http-equiv="Content-Type" content="text/html; charset=utf-8">'],
];
}

Expand Down Expand Up @@ -766,15 +766,15 @@ public function normalizedDocumentTypeDataProvider(): array
'HTML5, extra whitespace' => ['<!DOCTYPE html >', '<!DOCTYPE html>'],
'HTML 4 transitional, uppercase' => [
'<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" '
. '"http://www.w3.org/TR/REC-html40/loose.dtd">',
. '"http://www.w3.org/TR/REC-html40/loose.dtd">',
'<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" '
. '"http://www.w3.org/TR/REC-html40/loose.dtd">',
. '"http://www.w3.org/TR/REC-html40/loose.dtd">',
],
'HTML 4 transitional, lowercase' => [
'<!doctype html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" '
. '"http://www.w3.org/TR/REC-html40/loose.dtd">',
. '"http://www.w3.org/TR/REC-html40/loose.dtd">',
'<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" '
. '"http://www.w3.org/TR/REC-html40/loose.dtd">',
. '"http://www.w3.org/TR/REC-html40/loose.dtd">',
],
];
}
Expand Down Expand Up @@ -806,13 +806,13 @@ public function provideMalformedContentTypeMetaTag(): array
'extra character before META' => ['<xmeta http-equiv="Content-Type" content="text/html; charset=utf-8">'],
'extra character after META' => ['<metax http-equiv="Content-Type" content="text/html; charset=utf-8">'],
'extra character before HTTP-EQUIV'
=> ['<meta xhttp-equiv="Content-Type" content="text/html; charset=utf-8">'],
=> ['<meta xhttp-equiv="Content-Type" content="text/html; charset=utf-8">'],
'extra character after HTTP-EQUIV'
=> ['<meta http-equivx="Content-Type" content="text/html; charset=utf-8">'],
=> ['<meta http-equivx="Content-Type" content="text/html; charset=utf-8">'],
'extra character before CONTENT-TYPE'
=> ['<meta http-equiv=xContent-Type content="text/html; charset=utf-8">'],
=> ['<meta http-equiv=xContent-Type content="text/html; charset=utf-8">'],
'extra character after CONTENT-TYPE'
=> ['<meta http-equiv=Content-Typex content="text/html; charset=utf-8">'],
=> ['<meta http-equiv=Content-Typex content="text/html; charset=utf-8">'],
];
}

Expand Down Expand Up @@ -854,7 +854,7 @@ public function provideContentTypeMetaTag(): array
return [
'double-quoted attribute values' => ['<meta http-equiv="Content-Type" content="text/html; charset=utf-8">'],
'single-quoted attribute values'
=> ['<meta http-equiv=\'Content-Type\' content=\'text/html; charset=utf-8\'>'],
=> ['<meta http-equiv=\'Content-Type\' content=\'text/html; charset=utf-8\'>'],
'unquoted attribute values' => ['<meta http-equiv=Content-Type content=text/html;charset=utf-8>'],
'reverse order attributes' => ['<meta content="text/html; charset=utf-8" http-equiv="Content-Type">'],
'without charset' => ['<meta http-equiv="Content-Type" content="text/html">'],
Expand Down Expand Up @@ -887,23 +887,23 @@ public function provideHtmlAroundContentType(): array
'HEAD element with TAB after start tag' => ["<head>\t", '</head>'],
'HEAD element with attribute' => ['<head lang="en">', '</head>'],
'HTML, HEAD, and BODY with HEADER elements'
=> ['<html><head>', '</head><body><header></header></body></html>'],
=> ['<html><head>', '</head><body><header></header></body></html>'],
'HEAD element with comment' => ['<head><!--Test-->', '</head>'],
'HEAD element with commented-out BODY start tag' => ['<head><!--<body>-->', '</head>'],
'HEAD element with BASE element' => ['<head><base href="https://example.com"/>', '</head>'],
'HEAD element with COMMAND element' => ['<head><command type="command"/>', '</head>'],
'HEAD element with LINK element'
=> ['<head><link rel="stylesheet" href="https://example.org/css.css"/>', '</head>'],
=> ['<head><link rel="stylesheet" href="https://example.org/css.css"/>', '</head>'],
'HEAD element with another META element' => ['<head><meta name="title" content="Test"/>', '</head>'],
'HEAD element with NOSCRIPT element'
=> ['<head><noscript><style>p{color:green}</style></noscript>', '</head>'],
=> ['<head><noscript><style>p{color:green}</style></noscript>', '</head>'],
'HEAD element with SCRIPT element' => ['<head><script>console.log("Test");</script>', '</head>'],
'HEAD element with STYLE element' => ['<head><style>p{color:green}</style>', '</head>'],
'HEAD element with TEMPLATE element'
=> ['<head><template id="test"><p>Test</p></template></title>', '</head>'],
=> ['<head><template id="test"><p>Test</p></template></title>', '</head>'],
'HEAD element with TITLE element' => ['<head><title>Test</title>', '</head>'],
'HEAD element with uppercase TEMPLATE element'
=> ['<head><TEMPLATE id="test"><p>Test</p></TEMPLATE></title>', '</head>'],
=> ['<head><TEMPLATE id="test"><p>Test</p></TEMPLATE></title>', '</head>'],
'HEAD element with uppercase TITLE element' => ['<head><TITLE>Test</TITLE>', '</head>'],
'Second valid(ish) Content-Type in BODY' => [
'<head>',
Expand Down Expand Up @@ -1266,8 +1266,8 @@ private static function assertContainsHtml(string $needle, string $haystack, str
$needleMatcher = \preg_quote($needle, '%');
$needleMatcherWithNewlines = (new Preg())->replace(
'%\\\\<(?:body|ul|dl|optgroup|table|tr|hr'
. '|/(?:li|dd|dt|option|optgroup|caption|colgroup|thead|tbody|tfoot|tr|td|th'
. '|p|dl|h[1-6]|menu|ol|pre|table|ul|address|blockquote|div|fieldset|form))\\\\>%',
. '|/(?:li|dd|dt|option|optgroup|caption|colgroup|thead|tbody|tfoot|tr|td|th'
. '|p|dl|h[1-6]|menu|ol|pre|table|ul|address|blockquote|div|fieldset|form))\\\\>%',
'$0\\n?+',
$needleMatcher
);
Expand Down

0 comments on commit 101c2c8

Please sign in to comment.