From 9995d5ef7f0370eb41f327ca36dad5a40ea95f9d Mon Sep 17 00:00:00 2001 From: Nick Burgan-Illig Date: Thu, 24 Aug 2023 23:19:33 +0000 Subject: [PATCH] (maint) Fix valid_url? check Because the 'request' function does NOT return the value the block you pass it returns, this function was always returning a Net::HTTP object. With how this function was being used, it would result in valid_url? always being truthy. Net::HTTP.start DOES return the value that the block you pass it returns, though, so this simply un-blockifies the processing of the request response. --- lib/vanagon/component/source/http.rb | 27 +++++++++++++-------------- 1 file changed, 13 insertions(+), 14 deletions(-) diff --git a/lib/vanagon/component/source/http.rb b/lib/vanagon/component/source/http.rb index 083cf134..05097b1d 100644 --- a/lib/vanagon/component/source/http.rb +++ b/lib/vanagon/component/source/http.rb @@ -22,20 +22,19 @@ def valid_url?(target_url) return false unless ['http', 'https'].include? uri.scheme Net::HTTP.start(uri.host, uri.port, use_ssl: uri.scheme == 'https') do |http| - http.request(Net::HTTP::Head.new(uri)) do |response| - case response - when Net::HTTPRedirection - # By parsing the location header, we get either an absolute - # URI or a URI with a relative `path`. Adding it to `uri` - # should correctly update the relative `path` or overwrite - # the entire URI if it's absolute. - location = URI.parse(response.header['location']) - valid_url?(uri + location) - when Net::HTTPSuccess - return true - else - false - end + response = http.request(Net::HTTP::Head.new(uri)) + case response + when Net::HTTPRedirection + # By parsing the location header, we get either an absolute + # URI or a URI with a relative `path`. Adding it to `uri` + # should correctly update the relative `path` or overwrite + # the entire URI if it's absolute. + location = URI.parse(response.header['location']) + valid_url?(uri + location) + when Net::HTTPSuccess + true + else + false end end end