Skip to content

Commit

Permalink
URI.encode has been removed from Ruby 3
Browse files Browse the repository at this point in the history
Image caching were not working because the Image model silently decided
all image were "internal": the URI.encode (aka URI.escape) method does
not exist anymore in Ruby 3, which raised an error which where ignored
by the "rescue" line.

Instead of doing "URI.parse(URI.encode(str))", we are just doing
"URI.join(str)", because the join method converts firt the str to
RFC3986.

As this method does not raise error, the "rescue" part has been removed
too.
  • Loading branch information
Trim committed Mar 24, 2024
1 parent ee9cf0c commit 5875aff
Showing 1 changed file with 2 additions and 4 deletions.
6 changes: 2 additions & 4 deletions app/models/image.rb
Original file line number Diff line number Diff line change
Expand Up @@ -46,14 +46,12 @@ def register_in_redis
end

def internal_link?
uri = URI.parse(URI.encode link)
uri = URI.join(link)
!uri.host || uri.host == MY_DOMAIN || uri.host == IMG_DOMAIN
rescue
true
end

def blacklisted?
uri = URI.parse(URI.encode link)
uri = URI.join(link)
uri.host =~ /^(10|127|169\.254|192\.168)\./
end

Expand Down

0 comments on commit 5875aff

Please sign in to comment.