Mixed String and Symbol overrides send duplicate parameters

未关闭 适合新手
#45 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

@yorzi 已经在做这个了。

开始于 2026年11月17日。

  • #46 来自 @yorzi —— 未关闭
  • #47 来自 @yorzi —— 未关闭

评估

难度
2/5
预计耗时
1-3 小时
新手友好度
75/100
Issue 类型
缺陷
描述清晰度
描述清楚
活跃度
活跃
技术栈
ruby

调研方向

阅读lib/serpapi/client.rb,尤其是第64行的构造函数和第290行的query,以及README中关于参数覆盖的承诺。先在运行bundle install后执行issue中的复现步骤,然后检查现有的query覆盖和图片上传spec。完成标准是:混合使用String和Symbol键时,每个参数只发送覆盖后的值,并且测试涵盖普通参数和上传参数。

由索引模型根据 Issue 内容生成。

描述

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
主要语言
Ruby
星标
43
派生
27
平均合并
3 天 21 小时
30 天内合并 PR
5

环境准备

  • 没有 Dockerfile 或 Docker Compose 文件
  • 没有 Pull Request 模板
  • 阅读贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

serpapi/serpapi-ruby 的其他 Issue

查看 serpapi/serpapi-ruby 的全部 Issue

相似的 Issue

更多 Ruby Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。