Skip to content
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

Merged
merged 1 commit into from
Jun 19, 2014
Merged

Conversation

jdchmiel
Copy link

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.

$this->subject->setHtml($html);

$result = $this->subject->emogrify();
$this->assertContains($expected, $result);
Copy link
Contributor

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.)

@oliverklee
Copy link
Contributor

Hi, thanks for the pull request. Just two things:

a) for assertContains, the expected and the actual should be in separate lines each
b) Could you please prefix the commit message subject line with [BUGFIX] and make the first letter of the first word uppercase? Maybe you could also shorten the commit message to something like "[BUGFIX] Apply CSS attribute names in a case-insensitive way

@jdchmiel
Copy link
Author

It will take me a bit of time to get back to this, but yes, I will do so.

@oliverklee
Copy link
Contributor

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!

@jdchmiel
Copy link
Author

I am trying to figure out how to squash now.
..And I see the Travis error with preg_replace_callback...

@oliverklee
Copy link
Contributor

git rebase -i, and then mark all commits except for the first one with "s".

@oliverklee
Copy link
Contributor

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']));
Copy link
Author

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

@oliverklee
Copy link
Contributor

Could you also please add a unit tests that checks that the attribute values keep their case, e.g. content: "Hello world";?

@jdchmiel
Copy link
Author

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?

@oliverklee
Copy link
Contributor

I'd say we leave all attribute values unchanged to keep things simple.

@oliverklee
Copy link
Contributor

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.

@jdchmiel
Copy link
Author

This is my first exposure to travis, composer, and PHP Code sniffer.
I was running the commands I saw in the .travis.yml file, but that only works for the single version of PHP I have installed. I did not yet see if I can use composer to set up and specify additional PHP versions. The ; issue was me refactoring the format of the code and then forgetting to run the unit tests again. The preg_match /e issue is in php 5.5 which is odd as that dev box does have 5.5.3 but a zend version. I am still investigating that for curiosities sake. This is all peripheral work as time permits unfortunately, but I do appreciate your assistance and guidance to getting up to speed with this.

@jdchmiel
Copy link
Author

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..

@oliverklee
Copy link
Contributor

Hi, you can use the --force option when pushing if you have pushed before to that remote branch.

@jdchmiel
Copy link
Author

jdchmiel commented May 1, 2014

git reset --soft HEAD^
git push origin +master
I found this as the way to merge all of my commits into one.

@@ -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) {
Copy link
Contributor

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?

@jdchmiel
Copy link
Author

I ended up making the semicolon in each rule have a trailling space as well as the colon as it seemed more consistent. Thoughts?

@jdchmiel jdchmiel closed this Jun 18, 2014
@jdchmiel jdchmiel reopened this Jun 18, 2014
@oliverklee
Copy link
Contributor

Sounds good.

@@ -378,6 +363,25 @@ function (array $m) {
}
}


/**
* generateStyleStringFromDeclarationsArrays merges old or existing name/value array with new name/value array
Copy link
Contributor

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);
Copy link
Contributor

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

@oliverklee
Copy link
Contributor

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
@jdchmiel
Copy link
Author

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.

oliverklee added a commit that referenced this pull request Jun 19, 2014
Prevent incorrectly capitalized CSS selectors from being stripped
@oliverklee oliverklee merged commit 17eb967 into MyIntervals:master Jun 19, 2014
@oliverklee
Copy link
Contributor

Looks good. Thanks for this change!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants