Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

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

@thewilkybarkid thewilkybarkid referenced this pull request in FriendsOfPHP/Goutte May 9, 2014

Closed

Ignored Cookies on request domain #122

Member

stof commented May 9, 2014

👍

@Tobion Tobion commented on the diff May 9, 2014

src/Symfony/Component/BrowserKit/Cookie.php
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'], '/')) : '';
@Tobion

Tobion May 9, 2014

Member

substr can return false when path=''

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

@Tobion

Tobion May 9, 2014

Member

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

@thewilkybarkid

thewilkybarkid May 9, 2014

Contributor

No, but it can't happen here anyhow.

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

Member

Tobion commented May 9, 2014

👍

Owner

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