-
Notifications
You must be signed in to change notification settings - Fork 154
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Prevent incorrectly capitalized CSS selectors from being stripped #85
Conversation
$this->subject->setHtml($html); | ||
|
||
$result = $this->subject->emogrify(); | ||
$this->assertContains($expected, $result); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you please put the expected value and the actual value in separate lines each? (And if you like, you can inline $result.)
Hi, thanks for the pull request. Just two things: a) for assertContains, the expected and the actual should be in separate lines each |
It will take me a bit of time to get back to this, but yes, I will do so. |
Thanks! After you've re-pushed the pull request, could you please notify me here in the PR? GitHub does not notify me of re-pushes. :( Thanks! |
I am trying to figure out how to squash now. |
git rebase -i, and then mark all commits except for the first one with "s". |
Travis fails because the "e" modifier for preg_replace_callback is not allowed anymore in PHP 5.5. |
@@ -315,7 +315,7 @@ function (array $m) { | |||
|
|||
foreach ($this->caches[self::CACHE_KEY_CSS][$cssKey] as $value) { | |||
// query the body for the xpath selector | |||
$nodesMatchingCssSelectors = $xpath->query($this->translateCssToXpath(trim($value['selector']))); | |||
$nodesMatchingCssSelectors = $xpath->query($this->translateCssToXpath($value['selector'])); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
trim is done in translateCssToXpath
Could you also please add a unit tests that checks that the attribute values keep their case, e.g. content: "Hello world";? |
excellent point, it does undercase content. Is that the only exception or should we allow such things as: margin:0PX 1pX 2Px 3px; to pass through? |
I'd say we leave all attribute values unchanged to keep things simple. |
By the way, Jared, you can also run the unit tests and style checks on your local machine. This allows you to get quick feedback on your code without having to wait for Travis. |
This is my first exposure to travis, composer, and PHP Code sniffer. |
I think my rebase is not working out due to already pushing and then rebasing with things I had pushed already. I am way past the point of comfort with the amount of 'change' in one commit now though.. |
Hi, you can use the --force option when pushing if you have pushed before to that remote branch. |
git reset --soft HEAD^ |
@@ -596,6 +595,13 @@ private function getCssSelectorPrecedence($selector) { | |||
* @return string | |||
*/ | |||
private function translateCssToXpath($cssSelector) { | |||
$cssSelector = ' ' . $cssSelector . ' '; | |||
$cssSelector = preg_replace_callback('/\s+\w+\s+/', | |||
function($matches) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you please add the array type hint for the parameter?
I ended up making the semicolon in each rule have a trailling space as well as the colon as it seemed more consistent. Thoughts? |
Sounds good. |
@@ -378,6 +363,25 @@ function (array $m) { | |||
} | |||
} | |||
|
|||
|
|||
/** | |||
* generateStyleStringFromDeclarationsArrays merges old or existing name/value array with new name/value array |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
generateStyleStringFromDeclarationsArrays -> This method
* @return string | ||
*/ | ||
private function generateStyleStringFromDeclarationsArrays(array $oldStyles, array $newStyles) { | ||
$combinedArray = array_merge($oldStyles, $newStyles); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's have semantic variable names instead of named that include the type:
combinedArray -> combinedStyles or oldAndNewStyles
Could you also please squash both commits into one? |
…rcase attributes and selectors \#myID P { margin: 0px; } was not being applied correctly from style block p { MARGIN: 0PX; } was not being applied correctly from style block all inlined css from passed in css and parsed out <style> blocks is now lowercase [BUGFIX]Prevent incorrectly capitalized CSS selectors from being stripped Some wysiwyg editors seem to generate terrible CSS such as: P { PADDING: 0PX; MARGIN: 0PX; } which due to the capitalized P was not being applied inline. [BUGFIX] Apply CSS attribute names regardles of case, outputting lowercase attributes and selectors p { MARGIN: 0PX; } was not being applied correctly from style block all inlined css from passed in css and parsed out <style> blocks is now lowercase Prevent incorrectly capitalized CSS selectors from being stripped Some wysiwyg editors seem to generate terrible CSS such as: P { PADDING: 0PX; MARGIN: 0PX; } which due to the capitalized P was not being applied inline. fix my dumb replace deprecated preg_replace /e with preg_replace_callback to pass php 5.6 travis tests fix my dumb replace deprecated preg_replace /e with preg_replace_callback to pass php 5.6 travis tests Change undercase behavior to not change the case of the vss attribute value. Font names, content property (http://www.w3schools.com/cssref/pr_gen_content.asp) should be left alone. This fix exposes an inconsistency in the output CSS. Now all code paths output the css with no spacing around the : or ; which is breaking approx 25 unit tests that will be updated for the next commit. update the unit tests to expect no spaces in all resulting CSS instead of the mixed ouput based on what code path created it. update the regex to not skip when uppercase chars were present, added todo for possibly removing preg_match for less expensive explode. removed a few extra var_dumps I had left behind ran the .travis stuff manually to verify formatting / unit tests / lint and fixed formatting a bit, removed TODO but left comment in order to avoid generating a warning
I stripped out the unicode char I had added to two of the unit tests as that cannot pass until my next pull request. - These were the two you asked about single vs double quotes. |
Prevent incorrectly capitalized CSS selectors from being stripped
Looks good. Thanks for this change! |
Some wysiwyg editors seem to generate terrible CSS such as:
P {
PADDING: 0PX;
MARGIN: 0PX;
}
which due to the capitalized P was not being applied inline.