Skip to content

Add missing stdlib requires (time, base64, json) used by base_api / search / utils#593

Merged
const-cloudinary merged 1 commit intocloudinary:masterfrom
kai-matsudate:fix/missing-stdlib-requires
Apr 27, 2026
Merged

Add missing stdlib requires (time, base64, json) used by base_api / search / utils#593
const-cloudinary merged 1 commit intocloudinary:masterfrom
kai-matsudate:fix/missing-stdlib-requires

Conversation

@kai-matsudate
Copy link
Copy Markdown
Contributor

Brief Summary of Changes

lib/cloudinary/base_api.rb uses Time.parse and Base64.urlsafe_encode64. lib/cloudinary/utils.rb uses Base64.urlsafe_encode64 in several places. lib/cloudinary/search.rb calls both Base64.urlsafe_encode64 and JSON.generate from Search#to_url. None of those files require the corresponding stdlib at the top. The current test suite happens to preload time / base64 / json through spec_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 raise NoMethodError: undefined method 'parse' for class Time or NameError: uninitialized constant ...::Base64 / ...::JSON.

This PR adds the missing require lines: require "time" and require "base64" in base_api.rb, require "base64" in utils.rb, require "base64" and require "json" in search.rb. Same pattern as e2fb113 ("Add missing require 'net/http'"). Pure additive change — time, base64, and json are 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?

Are tests included?

  • Yes
  • No

Reviewer, please note:

  • The fix is five require statements at the top of three files: require "time" and require "base64" in lib/cloudinary/base_api.rb, require "base64" in lib/cloudinary/utils.rb, and require "base64" and require "json" in lib/cloudinary/search.rb. They're placed per file (rather than centrally in lib/cloudinary.rb) so each file under autoload stays self-contained — same approach as e2fb113.
  • No spec is included, mirroring e2fb113. The existing test suite stays green because spec_helper transitively loads these stdlibs anyway; the bug only surfaces in plain-Ruby cold-start, which bundle exec rspec doesn'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 rspec passes 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:

  • My code follows the code style of this project.
  • My change requires a change to the documentation.
  • I ran the full test suite before pushing the changes and all the tests pass.

`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.
@const-cloudinary const-cloudinary merged commit bdff100 into cloudinary:master Apr 27, 2026
7 checks passed
@const-cloudinary
Copy link
Copy Markdown
Member

@kai-matsudate thank you for contribution!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Missing stdlib requires (time, base64, json) cause cold-start NoMethodError / NameError

2 participants