Skip to content

Correct extension stripping #3757

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

Conversation

jaapromijn
Copy link
Contributor

@jaapromijn jaapromijn commented Feb 8, 2018

The removal of the extension of formats should only take place when
the format is present as extension in the url. (#3755)

Q A
Bug fix? yes
New feature? no
BC breaks? no
Deprecations? no
Fixed tickets fixes #3755
Related issues/PRs #3755
License MIT
Documentation PR sulu/sulu-docs#prnum

Why?

When using json as request format by default, without using .json extensions, the RouteProvider cut off the last character of the url, resulting in a 404.
In this PR, the stripping of the extension is only attempted if the format extension is present.

@jaapromijn jaapromijn force-pushed the issue-3755-strip-extension-from-path branch from f96bdb2 to f07930f Compare February 8, 2018 09:15
@wachterjohannes wachterjohannes self-requested a review February 8, 2018 10:08
@jaapromijn jaapromijn force-pushed the issue-3755-strip-extension-from-path branch from f07930f to 51e72aa Compare February 8, 2018 11:04
@jaapromijn jaapromijn changed the base branch from develop to master February 8, 2018 11:05
@jaapromijn jaapromijn force-pushed the issue-3755-strip-extension-from-path branch from 51e72aa to 0fa9b2b Compare February 8, 2018 13:57
Copy link
Member

@wachterjohannes wachterjohannes left a comment

Choose a reason for hiding this comment

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

@jaapromijn thanks for contribution - this looks already promising and it works :) but there are some things missing:

  • CHANGELOG.md entry
  • At least one testcase in Sulu\Bundle\SuluBundle\Tests\Unit\Routing\RouteProviderTest which is able to cover this usecase

@jaapromijn jaapromijn force-pushed the issue-3755-strip-extension-from-path branch from 408dd31 to 2cfcea2 Compare February 15, 2018 15:54
Jaap Romijn added 2 commits February 15, 2018 17:16
The removal of the extension of formats should only take place when
the format is present as extension in the url. (sulu#3755)
Add tests and a changelog entry for the extension stripping.
The removal of the extension of formats should only take place when
the format is present as extension in the url. (sulu#3755)
@jaapromijn jaapromijn force-pushed the issue-3755-strip-extension-from-path branch from 2cfcea2 to 146c7d2 Compare February 15, 2018 16:17
public function testGetRouteCollectionForRequestWithoutFormatExtension()
{
$request = $this->prophesize(Request::class);
$request->getPathInfo()->willReturn('/de/test');
Copy link
Member

Choose a reason for hiding this comment

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

i think the reuqest will return /de/test.json in a real-world example? didn't it?

Copy link
Contributor Author

@jaapromijn jaapromijn Feb 16, 2018

Choose a reason for hiding this comment

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

The use case is actually requesting a JSON page without using the .json extension.
The requested url for example is:

https://www.example.com/en/articles/foo-bar

And in my own request analyser the request format is set to json:

 $request->setRequestFormat('json');

So the path info should not return a path with a .json extension in this case? What you describe is already covered in another test, I think.

Copy link
Member

Choose a reason for hiding this comment

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

correct :) haven't recognized this - this PR is good! thanks for contribution

Copy link
Contributor Author

@jaapromijn jaapromijn Feb 16, 2018

Choose a reason for hiding this comment

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

👍 Thanks for the help!

@wachterjohannes wachterjohannes merged commit 7708f1b into sulu:master Feb 16, 2018
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.

2 participants