Skip to content

Commit

Permalink
[BUGFIX] Allow colons and semicolons in attribute value matchers
Browse files Browse the repository at this point in the history
Fixes #333
  • Loading branch information
oliverklee committed Feb 21, 2018
1 parent 088991b commit 9e77e76
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 1 deletion.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ This project adheres to [Semantic Versioning](https://semver.org/).
### Removed

### Fixed
- Allow colons and semicolons in attribute value matchers
([#???](https://github.com/MyIntervals/emogrifier/pull/???))
- Style property ordering when multiple mixed individual and shorthand
properties apply ([#511](https://github.com/MyIntervals/emogrifier/pull/511),
[#508](https://github.com/MyIntervals/emogrifier/issues/508))
Expand Down
2 changes: 1 addition & 1 deletion src/Emogrifier.php
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ class Emogrifier
// attribute presence
'/^\\[(\\w+|\\w+\\=[\'"]?\\w+[\'"]?)\\]/' => '*[@\\1]',
// type and attribute exact value
'/(\\w)\\[(\\w+)\\=[\'"]?([\\w\\s]+)[\'"]?\\]/' => '\\1[@\\2="\\3"]',
'/(\\w)\\[(\\w+)\\=[\'"]?([\\w \\:;\\-]+)[\'"]?\\]/' => '\\1[@\\2="\\3"]',
// type and attribute value with ~ (one word within a whitespace-separated list of words)
'/([\\w\\*]+)\\[(\\w+)[\\s]*\\~\\=[\\s]*[\'"]?([\\w-_\\/]+)[\'"]?\\]/'
=> '\\1[contains(concat(" ", @\\2, " "), concat(" ", "\\3", " "))]',
Expand Down
36 changes: 36 additions & 0 deletions tests/Unit/EmogrifierTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -434,6 +434,26 @@ public function matchedCssDataProvider()
'span[title=\'buenas dias bom dia\'] { %1$s }',
'<span title="buenas dias bom dia" style="%1$s">',
],
'type & attribute exact value => with type & exact attribute value match with colon' => [
'span[title="a:b"] { %1$s }',
'<span title="a:b" style="%1$s">',
],
'type & attribute exact value => with type & exact attribute value match with semicolon' => [
'span[title="c;d"] { %1$s }',
'<span title="c;d" style="%1$s">',
],
'type & attribute exact value => with type & exact attribute value match with hyphen' => [
'span[title="e-f"] { %1$s }',
'<span title="e-f" style="%1$s">',
],
'type & attribute exact value => with type & exact attribute value match with space' => [
'span[title=" "] { %1$s }',
'<span title=" " style="%1$s">',
],
'type & attribute exact value => with type & exact attribute value match with mixed special characters' => [
'span[title="a:b c;d e-f"] { %1$s }',
'<span title="a:b c;d e-f" style="%1$s">',
],
'type & attribute value with ~, double quotes => with type & exact attribute match' => [
'span[title~="bonjour"] { %1$s }',
'<span title="bonjour" style="%1$s">',
Expand Down Expand Up @@ -466,6 +486,10 @@ public function matchedCssDataProvider()
'span[title~="dia"] { %1$s }',
'<span title="buenas dias bom dia" style="%1$s">',
],
'type & attribute value with ~ => with type & word as 1st attribute with colon' => [
'span[title~="a:b"] { %1$s }',
'<span title="a:b c;d e-f" style="%1$s">',
],
'type & attribute value with |, double quotes => with exact match' => [
'span[title|="bonjour"] { %1$s }',
'<span title="bonjour" style="%1$s">',
Expand Down Expand Up @@ -507,6 +531,10 @@ public function matchedCssDataProvider()
'span[title^="buenas"] { %1$s }',
'<span title="buenas dias" style="%1$s">',
],
'type & attribute value with ^, double quotes => with match with colon' => [
'a[href^="https:"] { %1$s }',
'<a href="https://example.com/" style="%1$s">',
],
'type & attribute value with $, double quotes => with exact match' => [
'span[title$="bonjour"] { %1$s }',
'<span title="bonjour" style="%1$s">',
Expand All @@ -531,6 +559,10 @@ public function matchedCssDataProvider()
'span[title$="dias"] { %1$s }',
'<span title="buenas dias" style="%1$s">',
],
'type & attribute value with $, double quotes => with suffix math with semicolon' => [
'div[style$="0;"] { %1$s }',
'<div style="margin: 16px 0; %1$s">',
],
'type & two-word attribute value with *, double quotes => with exact match' => [
'span[title*="buenas dias"] { %1$s }',
'<span title="buenas dias" style="%1$s">',
Expand Down Expand Up @@ -559,6 +591,10 @@ public function matchedCssDataProvider()
'span[title*=": subtitle; author"] { %1$s }',
'<span title="title: subtitle; author" style="%1$s">',
],
'type & special characters attribute value with * => with substring match with colon' => [
'div[style*="in: 16px"] { %1$s }',
'<div style="margin: 16px 0; %1$s">',
],
'adjacent => 2nd of many' => ['p + p { %1$s }', '<p class="p-2" style="%1$s">'],
'adjacent => last of many' => ['p + p { %1$s }', '<p class="p-6" style="%1$s">'],
'adjacent (without space after +) => last of many' => ['p +p { %1$s }', '<p class="p-6" style="%1$s">'],
Expand Down

0 comments on commit 9e77e76

Please sign in to comment.