Add missing stdlib requires (time, base64, json) used by base_api / search / utils#593
Merged
const-cloudinary merged 1 commit intocloudinary:masterfrom Apr 27, 2026
Conversation
`lib/cloudinary/base_api.rb` calls `Time.parse` in
`Response#initialize` and `Base64.urlsafe_encode64` in
`get_authorization_header_value`. `lib/cloudinary/search.rb` calls
`Base64.urlsafe_encode64` and `JSON.generate` in `Search#to_url`.
`lib/cloudinary/utils.rb` calls `Base64.urlsafe_encode64` in
several places (e.g. signed URL generation). None of these files
require `time` / `base64` / `json` directly.
Historically this worked by accident because the test suite's
`spec_helper` pre-requires `active_storage/test_helper`, `nokogiri`,
and friends, which transitively load those stdlibs before
`cloudinary` is loaded. In a plain Ruby process — for example on
Ruby 4.0 — `require "cloudinary"` succeeds but the affected paths
fail:
NoMethodError: undefined method 'parse' for class Time
…/cloudinary/base_api.rb:30:in 'Cloudinary::BaseApi::Response#initialize'
NameError: uninitialized constant Cloudinary::Utils::Base64
…/cloudinary/utils.rb:620:in 'Cloudinary::Utils.cloudinary_url'
NameError: uninitialized constant Cloudinary::Search::Base64
…/cloudinary/search.rb:140:in 'Cloudinary::Search#to_url'
This follows the same pattern as e2fb113 ("Add missing
`require 'net/http'`"), adding the explicit stdlib `require` lines
that each affected file needs.
Member
|
@kai-matsudate thank you for contribution! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Brief Summary of Changes
lib/cloudinary/base_api.rbusesTime.parseandBase64.urlsafe_encode64.lib/cloudinary/utils.rbusesBase64.urlsafe_encode64in several places.lib/cloudinary/search.rbcalls bothBase64.urlsafe_encode64andJSON.generatefromSearch#to_url. None of those files require the corresponding stdlib at the top. The current test suite happens to preloadtime/base64/jsonthroughspec_helper(via Active Storage, Nokogiri and others), which is why CI stays green. In a plain Ruby process — for example on Ruby 4.0 —require "cloudinary"itself succeeds but the affected code paths raiseNoMethodError: undefined method 'parse' for class TimeorNameError: uninitialized constant ...::Base64/...::JSON.This PR adds the missing
requirelines:require "time"andrequire "base64"inbase_api.rb,require "base64"inutils.rb,require "base64"andrequire "json"insearch.rb. Same pattern as e2fb113 ("Add missingrequire 'net/http'"). Pure additive change —time,base64, andjsonare stdlib on every supported Ruby (>= 3, < 5), no behaviour or API change, and the gem still works the same with or without Rails.Closes #592.
What does this PR address?
time,base64,json) cause cold-startNoMethodError/NameError#592)Are tests included?
Reviewer, please note:
requirestatements at the top of three files:require "time"andrequire "base64"inlib/cloudinary/base_api.rb,require "base64"inlib/cloudinary/utils.rb, andrequire "base64"andrequire "json"inlib/cloudinary/search.rb. They're placed per file (rather than centrally inlib/cloudinary.rb) so each file underautoloadstays self-contained — same approach as e2fb113.spec_helpertransitively loads these stdlibs anyway; the bug only surfaces in plain-Ruby cold-start, whichbundle exec rspecdoesn't exercise. Happy to add a regression spec (e.g. spawning a child Ruby process per call path) if you'd like one.bundle exec rspecpasses locally. CI on this fork hasn't been triggered yet, so this PR will be the first run of the GitHub Actions matrix (Ruby 3.1.7 / 3.2.9 / 3.3.10 / 3.4.8 / 4.0.0). If maintainer approval is required for Actions on a first-time contributor PR, I'd appreciate it.Checklist: