From 016aa83e8f0660c7c246f0184b89613da2d40811 Mon Sep 17 00:00:00 2001 From: Danila Poyarkov Date: Thu, 5 Feb 2026 19:49:05 +0300 Subject: [PATCH 1/2] fix: replace CGI with URI for Ruby 4.0 compatibility CGI.parse and CGI.escape were removed in Ruby 4.0. Use URI.decode_www_form and URI.encode_www_form instead. Signed-off-by: Danila Poyarkov --- .../client/data_stores/direct_file_store.rb | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/lib/prometheus/client/data_stores/direct_file_store.rb b/lib/prometheus/client/data_stores/direct_file_store.rb index 1c09dc4d..05a506c6 100644 --- a/lib/prometheus/client/data_stores/direct_file_store.rb +++ b/lib/prometheus/client/data_stores/direct_file_store.rb @@ -1,5 +1,5 @@ require 'fileutils' -require "cgi" +require "uri" module Prometheus module Client @@ -133,12 +133,9 @@ def all_values begin store = FileMappedDict.new(file_path, true) store.all_values.each do |(labelset_qs, v, ts)| - # Labels come as a query string, and CGI::parse returns arrays for each key - # "foo=bar&x=y" => { "foo" => ["bar"], "x" => ["y"] } - # Turn the keys back into symbols, and remove the arrays - label_set = CGI::parse(labelset_qs).map do |k, vs| - [k.to_sym, vs.first] - end.to_h + # Labels come as a query string + # "foo=bar&x=y" => { foo: "bar", x: "y" } + label_set = URI.decode_www_form(labelset_qs).to_h.transform_keys(&:to_sym) stores_data[label_set] << [v, ts] end @@ -165,7 +162,7 @@ def store_key(labels) labels[:pid] = process_id end - labels.to_a.sort.map{|k,v| "#{CGI::escape(k.to_s)}=#{CGI::escape(v.to_s)}"}.join('&') + URI.encode_www_form(labels.to_a.sort) end def internal_store From 461b1ced32f8c5daa91705809f4651d79dbe2c67 Mon Sep 17 00:00:00 2001 From: Chris Sinjakli Date: Sun, 26 Jul 2026 01:18:20 +0100 Subject: [PATCH 2/2] Remove dependency on `cgi` This was introduced because `cgi` was moved out of the default gems in 4.0. It turns out we can simply use `uri`, which still ships with Ruby, for our purposes instead. Signed-off-by: Chris Sinjakli --- prometheus-client.gemspec | 1 - 1 file changed, 1 deletion(-) diff --git a/prometheus-client.gemspec b/prometheus-client.gemspec index 29aed5cf..549674f8 100644 --- a/prometheus-client.gemspec +++ b/prometheus-client.gemspec @@ -16,7 +16,6 @@ Gem::Specification.new do |s| s.require_paths = ['lib'] s.add_dependency 'base64' - s.add_dependency 'cgi' s.add_development_dependency 'benchmark' s.add_development_dependency 'benchmark-ips'