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

[Templating] Handle uri query strings passed to templating extension and helper #933

Closed
wants to merge 1 commit into from
Closed

[Templating] Handle uri query strings passed to templating extension and helper #933

wants to merge 1 commit into from

Conversation

rpkamp
Copy link
Contributor

@rpkamp rpkamp commented May 14, 2017

Q A
Branch? 1.0
Bug fix? yes
New feature? no
BC breaks? no
Deprecations? no
Tests pass? yes
Fixed tickets #903
License MIT

Gracefully handle any query strings in paths passed to the templating filters.
See added tests for behaviour.

@@ -40,7 +43,13 @@ public function __construct(CacheManager $cacheManager)
*/
public function filter($path, $filter, array $runtimeConfig = array())
{
return $this->cacheManager->getBrowserPath($path, $filter, $runtimeConfig);
$pathParts = explode('?', $path, 2);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'd love to hear a better name than $pathParts 🙄

I tried list($path, $queryString), which looks a lot better, but doesn't work when the original path doesn't contain a question mark (undefined index 1)

Choose a reason for hiding this comment

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

you can try this, to keep list function use.

list($path, $queryString) = array_pad(explode('?', $path, 2), 2, null);

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It works, but is quite hard to read IMO.

Choose a reason for hiding this comment

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

I agree, $pathParts sounds betters.

Waiting this merge.

@robfrawley
Copy link
Collaborator

We've discussed this in the past and one other idea brought up was to expose a configuration option that would enable this behavior. Also, isn't it possible that such handling should exist outside the templating component as well?

@rpkamp
Copy link
Contributor Author

rpkamp commented May 17, 2017

I consciously restricted the behaviour to the templating component because of the nature of templates, where it is easy to mix up paths and URLs. Other components should in my opinion only deal with paths and not concern themselves with query strings.

In terms of hexagonal architecture I think of the templating component as an infrastructure thing where user input is received that might be messy, whereas after that we enter the application layer, where input should be normalised to adhere to the application spec. So that is why I've made the templating component forgiving of query strings and fix them when sending them to the application and adding them back to the application response, but the rest of the bundle is still blissfully unaware of query strings.

@felipyamorim
Copy link

+1

@robfrawley robfrawley added this to the 1.8.1 milestone Jun 30, 2017
@robfrawley
Copy link
Collaborator

So, while I prefer this behavior over our current handling, I consider this a BC break. Many filesystems are happy to allow a filename such as "my-cool-image?with=an&odd=name.jpg" and this change would break such a usage.

As such, we need to default to the old behavior and add the ability to enable this behavior via a configuration toggle for the 1.x branch. This configuration option can then have its default changed on the 2.x branch to enable this handling by default.

I already have a commit that adds the configuration required to do this, and I'll push it to this PR shortly, as I'd like to include this in the next release. Just wanted to give everyone a heads up as to any progress.

@robfrawley robfrawley changed the title Handle query strings in paths passed to templating filters [Templating] Handle uri query strings passed to templating extension and helper Jul 13, 2017
@robfrawley robfrawley added Attn: BC Break This issue or PR results in a backwards-compatibility break and therefore requires a major release. Level: Enhancement ✨ This item involves an enhancement to existing functionality. State: Reviewing This item is being reviewed to determine if it should be accepted. labels Jul 13, 2017
@robfrawley robfrawley self-assigned this Jul 13, 2017
@robfrawley robfrawley modified the milestones: 1.9.1, 1.9.0 Aug 31, 2017
@robfrawley robfrawley modified the milestones: 1.9.2, 1.9.1 Sep 7, 2017
@rpkamp
Copy link
Contributor Author

rpkamp commented Nov 27, 2017

This PR has been open for a long time (since May of this year).
Anything I can do to advance the merging of this PR?

@makasim
Copy link
Collaborator

makasim commented Nov 27, 2017

As such, we need to default to the old behavior and add the ability to enable this behavior via a configuration toggle for the 1.x branch. This configuration option can then have its default changed on the 2.x branch to enable this handling by default.

@rpkamp you could as suggested by @robfrawley or simply change the base branch to 2.0

@rpkamp rpkamp changed the base branch from 1.0 to 2.0 November 28, 2017 08:53
@rpkamp rpkamp changed the base branch from 2.0 to 1.0 November 28, 2017 08:53
@rpkamp
Copy link
Contributor Author

rpkamp commented Dec 1, 2017

I've been thinking about this some more and have come to the conclusion that this PR solves the wrong problem. The problem is that the filter is applied to the output of asset, which is very inefficient as it would first copy the image from where-ever it is to the web root and then modify the copied image in the webroot.
So instead of allowing query strings in the render extensions we should discourage people from loading images using asset, but set up a correct loader for the path where there images are instead.

As such, I'm closing this PR.

@rpkamp rpkamp closed this Dec 1, 2017
@lsmith77 lsmith77 removed the State: Reviewing This item is being reviewed to determine if it should be accepted. label Dec 1, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Attn: BC Break This issue or PR results in a backwards-compatibility break and therefore requires a major release. Level: Enhancement ✨ This item involves an enhancement to existing functionality.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants