shrinerb / shrine

File Attachment toolkit for Ruby applications
https://shrinerb.com
MIT License
3.18k stars 275 forks source link

File download URL encoding mismatch #550

Closed vanboom closed 3 years ago

vanboom commented 3 years ago

Brief Description

When url is called for an attachment stored in Google Cloud Storage for a filename that includes a hash symbol, the URL encoding does not match what Google Cloud is expecting. We realize that this is somewhat of an edge case. The # character should not be used in filenames, but with modern file systems allowing it, please consider adding support in Shrine.

Expected behavior

When the filename includes a # symbol, it should be encoded as part of the filename and not an anchor.

e.g. "my#file.pdf" -> "my%23file.pdf"

https://storage.googleapis.com/`my_bucket`/attachments/file/my%23file.pdf

Actual behavior

Shrine does not URL encode the file name portion of the download URL...

https://storage.googleapis.com/`my_bucket`/attachments/file/my#file.pdf

Simplest self-contained example code to demonstrate issue

  1. Upload a file with a hash symbol in the name.
  2. Attempt to download it.

System configuration

Ruby version: 2.5.0

Shrine version: 3.4.0 shrine-google_cloud_storage: 1.34.1

Thanks for your consideration - I will attempt a PR if I can figure it out.

vanboom commented 3 years ago

Upon further investigation, the url is generated by the storage. So this issue applies to the shirine-google_cloud_storage plugin. Opened an issue here: https://github.com/renchap/shrine-google_cloud_storage/issues/47#issue-960920878