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

Fix InvalidArgumentException #392

Merged
merged 8 commits into from
Jun 30, 2017
Merged

Fix InvalidArgumentException #392

merged 8 commits into from
Jun 30, 2017

Conversation

jriboux
Copy link
Contributor

@jriboux jriboux commented Jun 22, 2017

Fix InvalidArgumentException when xpath does not find the css selector (eg: css3 keyframes).

You can reproduce the InvalidArgumentException using the following css :

@-moz-keyframes animate-stripes{
    0% {background-position: 0 0;} 100% {background-position: 60px 0;}
}

@oliverklee oliverklee self-requested a review June 22, 2017 10:51
@oliverklee oliverklee added the bug label Jun 22, 2017
@oliverklee oliverklee modified the milestones: 1.4.0, 1.3.0 Jun 22, 2017
@oliverklee
Copy link
Contributor

HI @jriboux, thanks a lot for the PR!

Could you please add a unit test that fails without the change and that passes with it? And could you also please add a line to the changelog file?

$nodesMatchingCssSelectors = $xPath->query($this->translateCssToXpath($cssRule['selector']));
} catch (\InvalidArgumentException $e) {
$nodesMatchingCssSelectors = false;
} // ignore invalid selectors
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please move this comment to above the catch (in its own line).

@jriboux
Copy link
Contributor Author

jriboux commented Jun 22, 2017

Sorry, my changes are in conflict with pull request #361 .
I need emogrify to ignore bad css selectors but developers should be able to debug.

Could we implement a debug switch, false by default that would :

  • Enable throws of InvalidArgumentException if true
  • Silence xpath errors if false

@oliverklee
Copy link
Contributor

Yes, a debug switch would be good. It should be off by default, and we should have a method public setDebug(bool $debug): void.

CHANGELOG.md Outdated
@@ -7,7 +7,7 @@ This project adheres to [Semantic Versioning](http://semver.org/).
## x.y.z (unreleased)

### Added

- Debug mode. Throw debug exceptions only if debug is active.
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 also please link the PR (i.e., use the same format as for the other changelog entries)?

@@ -226,6 +226,13 @@ class Emogrifier
];

/**
* If true, allow debug Exception to be thrown.
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 make this more specific: … Emogrifier will throw Exceptions when it encounters an error instead of silently ignoring them.

$line
)
);
if ($this->debug) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't need the else here as throwing an exception will exit the method anyway.

}

// the normal error handling continues when handler return false
return false;
}

/**
* Set debug mode.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please always use the third person for the first sentence of a method description: [This Method] "Sets the debug mode."

* Set debug mode.
*
* @param bool $debug set to true to enable debug mode
*/
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please also add the return void annotation.

$this->subject->emogrify();
}

/**
* @test
*/
public function emogrifyIgnoreInvalidCssSelectors()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please also add another test that tests for the behavior without debug mode.

Copy link
Contributor Author

@jriboux jriboux Jun 24, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To test with debug mode enabled I kept the test from pull request #361 "Handling invalid xPath expression warnings" and added the following line to test debug mode :
$this->subject->setDebug(true);
See lines 948 to 961

The test emogrifyIgnoreInvalidCssSelectors it the test with debug mode disabled.

@oliverklee oliverklee merged commit 941b491 into MyIntervals:master Jun 30, 2017
@oliverklee
Copy link
Contributor

Merged. Thanks for contributing to Emogrifier, @jriboux! ❤️

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

Successfully merging this pull request may close these issues.

3 participants