URI parser cannot parse `nil` path for CarrierWave::Storage::Fog::File#public_url

Author: tpdoganCreated Feb 8, 2024Updated Jan 8, 2025
Labelsbugneeds info

Hello there,

After upgrading to the latest version of carrierwave, CarrierWave::Storage::Fog::File#public_url started to raise undefined method 'gsub' for nil:NilClass for URI parser. It seems that this is due to this commit, which changed usage of path from path.to_s to path for #encode_path method. Thus, the use case of path being nil is not considered.

Following line https://github.com/carrierwaveuploader/carrierwave/blob/8b33235a0d5c0f06c429b8512529e99250e3aa2c/lib/carrierwave/utilities/uri.rb#L14

should be

ruby
URI::DEFAULT_PARSER.escape(path.to_s, PATH_UNSAFE)

Source: carrierwaveuploader/carrierwave