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

missing urlencode in build_srcset() to handle image filenames that contains whitespaces? #78

Open
ungual opened this issue Sep 19, 2023 · 2 comments

Comments

@ungual
Copy link

ungual commented Sep 19, 2023

I've recently had a problem using the plugin with image files that have whitespaces in their name. This gives no problem on the src attribute as it has no separator. However for responsive-images, the srcset attribute uses whitespaces as separator between filename and the width/pixel-density descriptor, hence images filename with whitespaces in them breaking the property parsing of the browser.

I was able to fix it by modifying the build_srcset() function.
I added a urlencoding to the filename using urllib.parse.quote(), as such

for src in process["srcset"]:
        file_path = posixpath.join(path.base_url, src[0], urllib.parse.quote(path.filename))
        srcset.append("%s %s" % (file_path, src[0]))
        destination = os.path.join(path.base_path, src[0], path.filename)
        process_image((path.source, destination, src[1]), settings)

should this become a feature, and if yes it probably need to be done for the whole path including parents folder, and with a little more care than this quick edit.

@MinchinWeb
Copy link
Member

If I understand this correctly, you're turning the space in the filename into %20, and then everything is happy?

@ungual
Copy link
Author

ungual commented Sep 19, 2023

yes exactly! however urlencoding the original images src doesn't work because image_process rewrite it anyways, so this step has to be done in the plugin itself as far as i understand

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

No branches or pull requests

2 participants