Skip to content

gh search code '"term"' sends the typed quotes escaped (q="\"term\"") and finds nothing #15060

Open

Description

@YevheniiKotyrlo

Describe the bug

A keyword in double quotes, as in GitHub's search syntax, reaches the API with its quotes escaped, so the search finds nothing. The escaping is the %q in quote().

This is one term in its own argument, not several qualifiers in one argument as in #13678.

Affected version

gh version 2.104.0 (2026-11-12) | MINGW64_NT-10.0-26300 3.6.10-5a1665c8.x86_64 x86_64

Windows 11, Git Bash.

Steps to reproduce the behavior

Reproducer: https://gist.github.com/YevheniiKotyrlo/772e3d949fafb16beaea0c86c7598aeb (bash repro.sh [path to gh]; the script exits 1 while the bug shows). It runs, against cli/cli:

  1. gh search code '"formatKeywords"' --repo cli/cli --limit 10 --json path --jq length prints 0.
  2. gh search code formatKeywords --repo cli/cli --limit 10 --json path --jq length prints 1.
  3. gh api -X GET search/code -f q='"formatKeywords" repo:cli/cli' --jq .total_count prints 1.
  4. GH_DEBUG=api gh search code '"formatKeywords"' --repo cli/cli --limit 1 requests q=%22%5C%22formatKeywords%5C%22%22+repo%3Acli%2Fcli.

Expected vs actual behavior

Expected: the quoted keyword reaches the API as typed, q="formatKeywords" repo:cli/cli, and finds what gh api finds for that query (1 result).

Actual: q="\"formatKeywords\"" repo:cli/cli, 0 results.

Logs

Output of bash repro.sh with gh 2.104.0:

$ gh search code '"formatKeywords"' --repo cli/cli --limit 10 --json path --jq length
0
$ gh search code formatKeywords --repo cli/cli --limit 10 --json path --jq length
1
$ gh api -X GET search/code -f q='"formatKeywords" repo:cli/cli' --jq .total_count
1
$ GH_DEBUG=api gh search code '"formatKeywords"' --repo cli/cli --limit 1   (request line)
/search/code?page=1&per_page=1&q=%22%5C%22formatKeywords%5C%22%22+repo%3Acli%2Fcli
q (decoded): "\"formatKeywords\"" repo:cli/cli

SUMMARY: DEFECT: gh search code '"formatKeywords"' --repo cli/cli sent q="\"formatKeywords\"" repo:cli/cli and returned 0 results; gh api with q="formatKeywords" repo:cli/cli returns total_count 1

Activity

  1. cli-triage commented on Nov 14, 2026

    @cli-triage

    Reproducible on 2.104.0.

    Using test data, the quoted keyword produced the reported request encoding:

    $ gh search code '"formatKeywords"' --repo example.invalid/hello --limit 10 --json path --jq length
    0

    Exit status: 0.

    The search command sent q="\"formatKeywords\"", while the equivalent gh api command sent q="formatKeywords" unchanged. Release 2.104.0 and source build source-3d5a9e3 behaved the same. The zero result used configured data; the confirmed defect is the extra escaping in the outgoing query. gh api is a workaround for exact quoted terms.

    Supporting reports

    Generated by issue triage.

  2. added
    bug
    gh-search
    priority-3
    on Nov 14, 2026
  3. removed
    needs-triage
    on Nov 14, 2026
  4. Daiyuanranfeng commented on Nov 16, 2026

    @Daiyuanranfeng

    I would like to take this issue. I will trace the search query quoting path, preserve literal quotes for a single search term while retaining qualifier handling, and add regression coverage for the API query sent by gh search code.

  5. added
    auto-bugfix-fixing
    on Nov 24, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    auto-bugfix-fixingbuggh-searchpriority-3

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions