Skip to content

Regex API term extraction discards quotes, causing regex queries to lose most matches #147

Description

@shouze

Parent epic: #146

Context and problem

Regex queries lose most of their expected results because the term sent to the GitHub API is too broad.

Reproduction: github-code-search '/"react":\s*"[~^]?[0-9]/' --org fulll returns only 2 results in the TUI, while the equivalent GitHub web search returns dozens of package.json files.

Root cause

longestLiteralSequence() in src/regex.ts only accumulates alphanumeric, underscore and hyphen characters. The double quote character always breaks the sequence, so the regex above currently yields the API term react, verified via direct API calls to return total_count 20288, mostly noise such as react-native, at-types react, docs and imports.

Solution

  • Extend longestLiteralSequence() in src/regex.ts to accumulate the double quote character as a valid literal character.
  • Before sending the extracted term to the API, escape each internal double quote and wrap the final term in double quotes, per GitHub's documented escaping syntax for quotes and backslashes.
  • Keep the function pure, with no I/O, per AGENTS.md.

Acceptance criteria

  • buildApiQuery for the pattern above produces an apiQuery equivalent to the escaped literal form, verified via direct API calls to return 117 to 126 results with zero noise.
  • Existing cases without quotes remain unchanged, the existing src/regex.test.ts suite stays green.
  • A new test covers the exact pattern from the reproduction and asserts the expected escaped apiQuery.

Definition of done

  • bun test passes, including the new regression test in src/regex.test.ts
  • bun run lint, bun run format:check, bun run knip pass
  • bun run build.ts compiles
  • Manual validation with the compiled binary on the reproduction command above

Files

  • src/regex.ts
  • src/regex.test.ts

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions