Skip to content
This repository has been archived by the owner on Jan 8, 2020. It is now read-only.

Hostname route should throw an exception if route definition contains disallowed character #6870

Closed
wants to merge 2 commits into from

Conversation

adamlundrigan
Copy link
Contributor

If a hostname route is constructed with a route containing a disallowed character (one outside of [a-z0-9-.]) a RuntimeException should be thrown, as the route is misconfigured.

Fixes #5656

@Ocramius Ocramius added this to the 2.4.0 milestone Nov 14, 2014
@Ocramius Ocramius self-assigned this Nov 14, 2014
@@ -116,6 +116,9 @@ protected function parseRouteDefinition($def)

while ($currentPos < $length) {
preg_match('(\G(?P<literal>[a-z0-9-.]*)(?P<token>[:{\[\]]|$))', $def, $matches, 0, $currentPos);
if (empty($matches)) {
Copy link
Member

Choose a reason for hiding this comment

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

@adamlundrigan doesn't preg_match() return a bool?

Copy link
Contributor

Choose a reason for hiding this comment

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

It returns a bool in case of an error. When there are not matches 0 is returned.

http://php.net/preg_match

preg_match() returns 1 if the pattern matches given subject, 0 if it does not, or FALSE if an error occurred.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

An alternative:

if ( 1 !== preg_match('(\G(?P<literal>[a-z0-9-.]*)(?P<token>[:{\[\]]|$))', $def, $matches, 0, $currentPos) ) {
    throw new Exception\RuntimeException('Matched hostname literal contains a disallowed character');
}

Functionally identical, just all on one line. @Ocramius I can update the PR if you'd prefer I check the result this way.

Choose a reason for hiding this comment

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

Why so complicated?

// No matches found, or error occured - distinction not necessary, as both cases are actually faulty here
if (!preg_match(..., $matches, ...)) {
    throw ...;
}
// else: We DO have $matches here

Copy link
Member

Choose a reason for hiding this comment

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

Indeed, I think @Pittiplatsch's approach is good enuff.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed

Ocramius added a commit that referenced this pull request Nov 22, 2014
@Ocramius
Copy link
Member

@adamlundrigan merged into develop at d22bf92, thanks!

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

Successfully merging this pull request may close these issues.

undefines indexes on hostname route
4 participants