Skip to content

Commit 4357ee9

Browse files
rounak610claude
andcommitted
Add comment explaining each guard in validate_source_url
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent c0e8306 commit 4357ee9

1 file changed

Lines changed: 5 additions & 0 deletions

File tree

lib/browserstack/fetch_download_source_url.rb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,11 @@ module FetchDownloadSourceUrl
1111
ALLOWED_DOWNLOAD_HOSTS = ['browserstack.com'].freeze
1212
ALLOWED_DOWNLOAD_HOST_SUFFIXES = ['.browserstack.com'].freeze
1313

14+
# Each guard below covers a case the final host-equals check does not:
15+
# - nil/empty URL: URI.parse(nil) raises TypeError before the rescue can catch it.
16+
# - URI::InvalidURIError: convert raw Ruby error into BrowserStack::LocalException for the public contract.
17+
# - HTTPS check: allowlist matches host only; without this, http://browserstack.com would pass.
18+
# - nil/empty host: uri.host is nil for URIs like https:///foo, which would crash on downcase.
1419
def self.validate_source_url(url)
1520
if url.nil? || url.to_s.empty?
1621
raise BrowserStack::LocalException.new('Refusing binary download: empty source URL')

0 commit comments

Comments
 (0)