Skip to content

Commit

Permalink
Apply suggestions from code review
Browse files Browse the repository at this point in the history
Co-authored-by: Luis H. Ball Jr. <luqven@gmail.com>
  • Loading branch information
pypas and luqven committed Oct 18, 2022
1 parent bc99584 commit b9405d1
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 11 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
17 changes: 8 additions & 9 deletions lib/imgix/path.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion test/units/srcset_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down

0 comments on commit b9405d1

Please sign in to comment.