Skip to content

Commit

Permalink
[BUGFIX] Dynamic and static pseudo-class combined (#746)
Browse files Browse the repository at this point in the history
The regular expression in `PSEUDO_CLASS_MATCHER` would match, e.g.,
`:hover:first-child` as a supported pseudo-class because it was consuming any
non-space character as being valid in a pseudo-class name.  This has been
corrected so that it only consumes ‘word’ characters and hyphens.
  • Loading branch information
JakeQZ authored and oliverklee committed Sep 29, 2019
1 parent c682802 commit 81afdc0
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 2 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,8 @@ This project adheres to [Semantic Versioning](https://semver.org/).
([#690](https://github.com/MyIntervals/emogrifier/pull/690))

### Fixed
- Dynamic pseudo-class combined with static one (rules copied to `<style>`
element, [#746](https://github.com/MyIntervals/emogrifier/pull/746))
- Descendant attribute selectors (such as `html input[disabled]`)
([#375](https://github.com/MyIntervals/emogrifier/pull/375),
[#709](https://github.com/MyIntervals/emogrifier/pull/709))
Expand Down
2 changes: 1 addition & 1 deletion src/Emogrifier.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ class Emogrifier
*
* @var string
*/
const PSEUDO_CLASS_MATCHER = '\\S+\\-(?:child|type\\()|not\\([[:ascii:]]*\\)';
const PSEUDO_CLASS_MATCHER = '[\\w\\-]+\\-(?:child|type\\()|not\\([[:ascii:]]*\\)';

/**
* @var string
Expand Down
2 changes: 1 addition & 1 deletion src/Emogrifier/CssInliner.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ class CssInliner extends AbstractHtmlProcessor
*
* @var string
*/
const PSEUDO_CLASS_MATCHER = '\\S+\\-(?:child|type\\()|not\\([[:ascii:]]*\\)';
const PSEUDO_CLASS_MATCHER = '[\\w\\-]+\\-(?:child|type\\()|not\\([[:ascii:]]*\\)';

/**
* @var bool[]
Expand Down
2 changes: 2 additions & 0 deletions tests/Unit/CssInlinerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -1894,6 +1894,8 @@ public function matchingSelectorWithPseudoComponentCssRuleDataProvider()
'pseudo-class & pseudo-element' => ['a:hover::after { content: "bar"; }'],
'pseudo-element & pseudo-class' => ['a::after:hover { content: "bar"; }'],
'two pseudo-classes' => ['a:focus:hover { color: green; }'],
'dynamic and static pseudo-classes' => ['a:hover:first-child { color: green; }'],
'static and dynamic pseudo-classes' => ['a:first-child:hover { color: green; }'],
];

return \array_merge($datasetsWithSelectorPseudoComponents, $datasetsWithCombinedPseudoSelectors);
Expand Down
2 changes: 2 additions & 0 deletions tests/Unit/EmogrifierTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2042,6 +2042,8 @@ public function matchingSelectorWithPseudoComponentCssRuleDataProvider()
'pseudo-class & pseudo-element' => ['a:hover::after { content: "bar"; }'],
'pseudo-element & pseudo-class' => ['a::after:hover { content: "bar"; }'],
'two pseudo-classes' => ['a:focus:hover { color: green; }'],
'dynamic and static pseudo-classes' => ['a:hover:first-child { color: green; }'],
'static and dynamic pseudo-classes' => ['a:first-child:hover { color: green; }'],
];

return \array_merge($datasetsWithSelectorPseudoComponents, $datasetsWithCombinedPseudoSelectors);
Expand Down

0 comments on commit 81afdc0

Please sign in to comment.