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

[BrowserKit] Allow URLs that don't contain a path when creating a cookie from a string #10762

Merged
merged 1 commit into from May 9, 2014

Conversation

Projects
None yet
4 participants
@thewilkybarkid
Contributor

thewilkybarkid commented Apr 22, 2014

Q A
Bug fix? yes
New feature? no
BC breaks? no
Deprecations? no
Tests pass? yes
Fixed tickets
License MIT
Doc PR

The Cookie class doesn't require a path, but the fromString() static method does, so when URL given is something like http://www.example.com (ie no trailing slash) it currently throws an exception. This PR removes the requirement.

@stof

This comment has been minimized.

Member

stof commented May 9, 2014

👍

throw new \InvalidArgumentException(sprintf('The URL "%s" is not valid.', $url));
}
$values['domain'] = $urlParts['host'];
$values['path'] = substr($urlParts['path'], 0, strrpos($urlParts['path'], '/'));
$values['path'] = isset($urlParts['path']) ? substr($urlParts['path'], 0, strrpos($urlParts['path'], '/')) : '';

This comment has been minimized.

@Tobion

Tobion May 9, 2014

Member

substr can return false when path=''

This comment has been minimized.

@thewilkybarkid

thewilkybarkid May 9, 2014

Contributor

It can never be an empty string as parse_url() won't included it if it isn't there.

(Even if it does happen it's not a problem at the moment as it's caught by the constructor's empty()).

This comment has been minimized.

@Tobion

Tobion May 9, 2014

Member

@param string $path The path passing false is not officially supported

This comment has been minimized.

@thewilkybarkid

thewilkybarkid May 9, 2014

Contributor

No, but it can't happen here anyhow.

This comment has been minimized.

@stof

stof May 9, 2014

Member

@Tobion If there is no path in the URL, parse_url will not put an empty string in $urlParts['path']. It will not set the path key at all, so it won't reach the substr call.

@Tobion

This comment has been minimized.

Member

Tobion commented May 9, 2014

👍

@fabpot

This comment has been minimized.

Member

fabpot commented May 9, 2014

Thank you @thewilkybarkid.

@fabpot fabpot merged commit fc1223f into symfony:2.3 May 9, 2014

2 checks passed

continuous-integration/travis-ci The Travis CI build passed
Details
default Success: Travis, fabbot
Details

fabpot added a commit that referenced this pull request May 9, 2014

bug #10762 [BrowserKit] Allow URLs that don't contain a path when cre…
…ating a cookie from a string (thewilkybarkid)

This PR was merged into the 2.3 branch.

Discussion
----------

[BrowserKit] Allow URLs that don't contain a path when creating a cookie from a string

| Q             | A
| ------------- | ---
| Bug fix?      | yes
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets |
| License       | MIT
| Doc PR        |

The Cookie class doesn't require a path, but the `fromString()` static method does, so when URL given is something like http://www.example.com (ie no trailing slash) it currently throws an exception. This PR removes the requirement.

Commits
-------

fc1223f Allow URLs that don't contain a path

@thewilkybarkid thewilkybarkid deleted the thewilkybarkid:cookie-pathless-url branch Jul 8, 2014

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