Skip to content

Test and do not add leading slash when there is one already #5473 #5511

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

Merged
merged 1 commit into from
Jun 15, 2019
Merged

Test and do not add leading slash when there is one already #5473 #5511

merged 1 commit into from
Jun 15, 2019

Conversation

nicholascus
Copy link
Contributor

@nicholascus nicholascus commented May 18, 2019

Redo url parts concatenations the right way.
Moved forward slash prefixing out of the branch to the main level of the function as that would be more consistent behaviour between cases when config['url'] set and empty... though I would rather remove that slash prefixing altogether L583-L585.

This is redo of #5474

@nicholascus
Copy link
Contributor Author

nicholascus commented May 24, 2019

I put together some test cases.
I'm actually suggesting to remove changes done in #4796, and leave that to user to explicitly pass forward slashes in the beginning of the config url.

Below is the result of this PR test cases execution on codeception-2.6, which explain the change.

Test cases ($configUrl, $requestUrl, $expectedFullUrl):
('v1/', 'healthCheck', 'v1/healthCheck') // this is different in current 2.6; #4796 introduced autoprefixing of config value with forward slash. I'm suggesting to undo that.
('/v1', '/healthCheck', '/v1/healthCheck')
('v1', 'healthCheck', 'v1/healthCheck') //this is different in current 2.6
('http://v1/', '/healthCheck', 'http://v1/healthCheck') // I really been fixing this
('http://v1', 'healthCheck', 'http://v1/healthCheck') //this is different in current 2.6
('http://v1', 'http://v2/healthCheck', 'http://v2/healthCheck')
('http://v1', '', 'http://v1')
('http://v1', '/', 'http://v1/')
('', 'http://v1', 'http://v1')
('', 'healthCheck', 'healthCheck')
('/', 'healthCheck', '/healthCheck')

`
git checkout 2.6
codeception on 2.6 [$]
git checkout bug-5473-rest-module-doubles-leading-slashes -- tests/unit/Codeception/Module/RestTest.php
codeception on 2.6 [!$]
$ php codecept run tests/unit/Codeception/Module/RestTest.php:testRestExecute
Codeception PHP Testing Framework v2.6.0
Powered by PHPUnit 7.5.8 by Sebastian Bergmann and contributors.
Running with seed:

[Seed] 1411564475

Unit Tests (11) ------------------------
✖ RestTest: Rest execute | #0 (0.11s)
✔ RestTest: Rest execute | #1 (0.00s)
✖ RestTest: Rest execute | #2 (0.00s)
✖ RestTest: Rest execute | #3 (0.00s)
✖ RestTest: Rest execute | #4 (0.00s)
✔ RestTest: Rest execute | #5 (0.00s)
✔ RestTest: Rest execute | #6 (0.01s)
✔ RestTest: Rest execute | #7 (0.00s)
✔ RestTest: Rest execute | #8 (0.01s)
✔ RestTest: Rest execute | #9 (0.00s)
✔ RestTest: Rest execute | #10 (0.01s)

Time: 769 ms, Memory: 12.00 MB

There were 4 failures:


  1. RestTest: Rest execute | #0
    Test tests/unit/Codeception/Module/RestTest.php:testRestExecute
    Failed asserting that two strings are equal.

  1. RestTest: Rest execute | I haven't tested this in enough varying circumstances, but this fixed a number of failure-to-execute problems for me... #2
    Test tests/unit/Codeception/Module/RestTest.php:testRestExecute
    Failed asserting that two strings are equal.

  1. RestTest: Rest execute | UTF-8 bugs #3
    Test tests/unit/Codeception/Module/RestTest.php:testRestExecute
    Failed asserting that two strings are equal.

  1. RestTest: Rest execute | seeLink and dontSeeLink #4
    Test tests/unit/Codeception/Module/RestTest.php:testRestExecute
    Failed asserting that two strings are equal.

FAILURES!
Tests: 11, Assertions: 18, Failures: 4.
`

$url = '/' . $url;
}
if (strpos($url, '://') === false && $this->config['url']) {
$url = rtrim($this->config['url'], '/') . ($url && $this->config['url'] ? '/' : '') . ltrim($url, '/');
Copy link
Member

Choose a reason for hiding this comment

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

There is no need to check $this->config['url'] in ternary operator, it was checked in a previous line.
Another edge case to test is when there is a trailing slash in config['url'] - array('http://v1/', '', 'http://v1/'),
removing the slash could be a wrong thing to do, right?

Copy link
Member

Choose a reason for hiding this comment

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

How about handling empty $url as a special case?

if ($url === '') {
  $url = $this->config['url'];
} else {
  $url = rtrim($this->config['url'], '/') . '/' . ltrim($url, '/')
}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

sure, done.

…s. Removed autoprefixing of url with slash, as that should be done by users explicitely.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants