From 3eda5c60663a5882e06b7b09d438cef3aeb15fc2 Mon Sep 17 00:00:00 2001 From: Danila Poyarkov Date: Thu, 5 Feb 2026 19:49:05 +0300 Subject: [PATCH] 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