Liipimaginebundle: Cache resolution fails if file name contains a plus (+)

Created on 8 Dec 2018  路  7Comments  路  Source: liip/LiipImagineBundle

Preconditions


  1. LiipImagineBundle 2.1
  2. PHP 7.2

Steps to reproduce

  1. Try resolving a file named "test+file.jpg". Eg:
    {{ "uploads/test+file.jpg" | imagine_filter('thumb') }}

Expected result

  • Resolved image

Actual result

  • Error" Source image for path "uploads/test file.jpg" could not be found

Most helpful comment

@anderageru, @sujayjaju PR is created

All 7 comments

Same issue if there is a hash (#) in the file name

A hash has a special context in a browser; same with a plus. You would need to encode the URL path for it to work properly.

@robfrawley
Yes, but the problem is that the imagine_filter double encodes the file name, if the encoded name is passed to the filter. The solution that worked was to extract just the file name from the url returned by the filter and replaced it with the encoded version. That seems like quite a convoluted solution. Should the filter handle those cases?

@sujayjaju I have the same issue. The problem is that \Liip\ImagineBundle\Imagine\Cache\Resolver\ResolverInterface::resolve method implementations (WebPathResolver and probably others) do not expect that file system path might contain special characters. In case of URL, most of these characters should be encoded.

Probably the proper fix will be to convert filesystem path to URL path inside resolve() method implemenations in following way:

implode('/', array_map('rawurlencode', explode('/', $path)))

I can confirm @torinaki's solution fixes this issue. Care to submit a PR for this?

@anderageru, @sujayjaju PR is created

Fixed in #1162

Was this page helpful?
0 / 5 - 0 ratings