Mixed String and Symbol overrides send duplicate parameters

Đang mở Phù hợp với người mới
#45 0 bình luận 0 reaction 0 người được giao Xem trên GitHub

@yorzi đang làm issue này rồi.

Từ ngày 17/11/2026.

  • #46 của @yorzi — đang mở
  • #47 của @yorzi — đang mở

Đánh giá

Độ khó
2/5
Thời gian dự kiến
1-3 giờ
Mức phù hợp với người mới
75/100
Loại issue
Lỗi
Độ rõ ràng
Đặc tả rõ ràng
Mức độ hoạt động
Sôi nổi
Công nghệ
ruby
Lĩnh vực
backend-api-design

Hướng nghiên cứu

Đọc lib/serpapi/client.rb, đặc biệt là constructor ở dòng 64 và query ở dòng 290, cùng với cam kết trong README về việc ghi đè tham số. Bắt đầu bằng cách chạy cách tái hiện trong issue sau khi bundle install, rồi kiểm tra các spec hiện có về việc ghi đè query và tải ảnh lên. Hoàn thành khi các khóa String và Symbol kết hợp chỉ gửi giá trị ghi đè cho từng tham số, với các bài kiểm tra bao gồm cả tham số thông thường và tham số tải lên.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

Basic checks
  • I searched existing issues, open and closed, and found no general mixed-key override fix
  • I can reproduce this consistently on master
  • This is a serpapi-ruby bug, not my application code
What's broken?

The constructor accepts String and Symbol keys
(lib/serpapi/client.rb:64), and README.md:88-117 promises that per-call
parameters override defaults. But query at client.rb:290 merges raw
Ruby Hash keys. If the call and default use different key types, both
reach HTTP.rb and are encoded with the same parameter name.

This affects engines, API-key overrides, nil overrides, and arbitrary
backend fields. It also affects image-upload form fields. A default that
should have been replaced is still sent. No particular server-side
precedence for duplicate parameters is assumed.

#29 already handles
this for output, and #37
handles Extract's forced engine. This report concerns ordinary overrides.
It does not include the Hash mutation in
#39 or error policy in
#42.

How to reproduce

From the repository root, after bundle install. HTTP.rb builds the real
request; perform is intercepted before network I/O:

bundle exec ruby -Ilib - <<'RUBY'
require 'serpapi'

response = Struct.new(:status, :headers, :body).new(
  200, { 'Content-Type' => 'application/json' }, '{}'
)
transport = HTTP::Client.new
transport.define_singleton_method(:perform) do |request, _options|
  p request.uri.query_values(Array).select { |key, _| key == 'engine' }
  response
end
HTTP.define_singleton_method(:timeout) { |_timeout| transport }
client = SerpApi::Client.new('engine' => 'google', persistent: false)
client.search(engine: 'bing')
RUBY
Expected behavior
[["engine", "bing"]]
What actually happened
[["engine", "google"], ["engine", "bing"]]

I have a small local fix with tests and can open a PR.

Environment
  • Ruby 3.4.4, macOS arm64
  • serpapi-ruby master at 786baa6848020df031abed734ed7ff03af3a6560
  • HTTP.rb 5.3.1, RSpec 3.13.2
  • No API credentials, external requests, or search credits used
Ngôn ngữ chính
Ruby
Star
43
Fork
27
Merge trung bình
3 ngày 21 giờ
Pull request đã merge (30 ngày)
5

Chuẩn bị môi trường

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của serpapi/serpapi-ruby

Tất cả issue của serpapi/serpapi-ruby

Issue tương tự

Thêm issue về Ruby

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.