From b9405d10d30aaf3a71efb7092b1a25fcaeed8987 Mon Sep 17 00:00:00 2001 From: Paula Pasqualini <52749105+pypas@users.noreply.github.com> Date: Tue, 18 Oct 2022 14:01:13 +0200 Subject: [PATCH] Apply suggestions from code review Co-authored-by: Luis H. Ball Jr. --- README.md | 2 +- lib/imgix/path.rb | 17 ++++++++--------- test/units/srcset_test.rb | 2 +- 3 files changed, 10 insertions(+), 11 deletions(-) diff --git a/README.md b/README.md index 16ff7e1..00b0383 100644 --- a/README.md +++ b/README.md @@ -64,7 +64,7 @@ client.path('/[images]/demo.png').to_url #=> https://your-subdomain.imgix.net/%5Bimages%5D/demo.png?s=270832685733a36ba02bd8ab9fd72df5 client.path('/[images]/demo.png').to_url({},{disable_path_encoding: true}) #=> https://your-subdomain.imgix.net/[images]/demo.png?s=ed6eb07e9eff3f6c8bbcc83fc4f63198 - +``` ## Srcset Generation The imgix gem allows for generation of custom `srcset` attributes, which can be invoked through `Imgix::Path#to_srcset`. By default, the `srcset` generated will allow for responsive size switching by building a list of image-width mappings. diff --git a/lib/imgix/path.rb b/lib/imgix/path.rb index add1eeb..1173cc6 100644 --- a/lib/imgix/path.rb +++ b/lib/imgix/path.rb @@ -135,16 +135,15 @@ def method_missing(method, *args, &block) def sanitize_path(path, options = {}) # remove the leading "/", we'll add it back after encoding path = path.slice(1, path.length) if Regexp.new('^/') =~ path - if !options[:disable_path_encoding] - # if path is being used as a proxy, encode the entire thing - if /^https?/ =~ path - return encode_URI_Component(path) - else - # otherwise, encode only specific characters - return encode_URI(path) - end + if options[:disable_path_encoding] + return "/" + path + # if path is being used as a proxy, encode the entire thing + elsif /^https?/ =~ path + return encode_URI_Component(path) + else + # otherwise, encode only specific characters + return encode_URI(path) end - return "/" + path end # URL encode the entire path diff --git a/test/units/srcset_test.rb b/test/units/srcset_test.rb index 3473011..52dd5d9 100644 --- a/test/units/srcset_test.rb +++ b/test/units/srcset_test.rb @@ -764,7 +764,7 @@ def srcset class SrcsetDisablePathEncoding < Imgix::Test include SrcsetTest - def test_enable_path_encoding + def test_encode_path_by_default srcset = mock_client.to_srcset src = srcset.split(" ")[0] assert_equal(src, "https://testing.imgix.net/%5Bimage%5D.jpg?w=100")