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 double slashes in certain forms submitted by InnerBrowser::submitForm #1625

Merged

Conversation

@Revisor
Copy link
Contributor

@Revisor Revisor commented Jan 5, 2015

The Codeception\Lib\InnerBrowser method getFormUrl() can under certain
conditions create a form URL where the path begins with double slashes.

Conditions for the error:

  1. The page with the form lies on a first-level path, e.g.
    example.com/register
  2. The form has an action without a leading slash, e.g.

This is valid and browsers understand what is meant.

On Unix the malformed action URL will look like this:
http://example.com//form-target

On Windows this is even worse because dirname() of a first-level directory
returns a backslash () instead of a forward slash.

See http://www.webmasterworld.com/php/3752500.htm

Thus a form URL with Codeception run on Windows will look like this:
http://example.com/\/form-target

Both malformed URLs can cause server errors, depending on the server
configuration mostly 404 or 500.

This commit adds a test that confirms the error and fixes it
in a localized way that shouldn't regress anything else.

…Form()

The Codeception\Lib\InnerBrowser method getFormUrl() can under certain
conditions create a form URL where the path begins with double slashes.

Conditions for the error:
1. The page with the form lies on a first-level path, e.g.
example.com/register
2. The form has an action without a leading slash, e.g.
<form action="login">

This is valid and browsers understand what is meant.

On Unix the malformed action URL will look like this:
http://example.com//form-target

On Windows this is even worse because dirname() of a first-level directory
returns a backslash (\) instead of a forward slash.

See http://www.webmasterworld.com/php/3752500.htm

Thus a form URL with Codeception run on Windows will look like this:
http://example.com/\/form-target

Both malformed URLs can cause server errors, depending on the server
configuration mostly 404 or 500.

This commit adds a test that confirms the error and fixes it
in a localized way that shouldn't regress anything else.
@zbateson
Copy link
Member

@zbateson zbateson commented Jan 23, 2015

Nice catch, thanks Revisor.

It could be made to catch more possibilities and leaner with a nicely placed rtrim instead of the conditional though - what do you think of:

$dir = rtrim(dirname($build[$part]), '\\/') . '/' . $value;

That way any extra trailing forward or back slashes would be trimmed regardless.

Thanks again! 👍

@DavertMik
Copy link
Member

@DavertMik DavertMik commented Jan 24, 2015

Thanks! Merging your pull request, and I think I will try so simplify with @zbateson suggestion.

DavertMik added a commit that referenced this pull request Jan 24, 2015
…windows

Fix double slashes in certain forms submitted by InnerBrowser::submitForm
@DavertMik DavertMik merged commit cdb4e07 into Codeception:2.0 Jan 24, 2015
1 check failed
1 check failed
continuous-integration/travis-ci The Travis CI build failed
Details
DavertMik added a commit that referenced this pull request Jan 24, 2015
@Revisor
Copy link
Contributor Author

@Revisor Revisor commented Jan 24, 2015

Thank you both for simplifying and accepting the fix.

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

Successfully merging this pull request may close these issues.

None yet

3 participants
You can’t perform that action at this time.