Fail fast on unbalanced quotes in plain-text queries - #153
Conversation
cc070de to
af9a0ca
Compare
|
Coverage after merging fix/plain-text-quote-validation into fix/regex-api-term-quotes will be
Coverage Report
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
There was a problem hiding this comment.
Pull request overview
This PR adds local validation to fail fast on plain-text GitHub code-search queries that contain an odd number of unescaped double quotes, preventing opaque GitHub API 422 ERROR_TYPE_QUERY_PARSING_FATAL failures and reducing confusing false-positive behavior.
Changes:
- Added
validateQuoteBalance()insrc/regex.tsto detect unbalanced (unescaped)"in non-regex queries and return an actionable error message. - Wired quote-balance validation into the CLI (
github-code-search.ts) so the program exits before any API call. - Added unit tests in
src/regex.test.tscovering balanced/unbalanced/escaped inputs and a regex-bypass case.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
src/regex.ts |
Introduces quote-balance validation logic for plain-text queries. |
src/regex.test.ts |
Adds unit tests for the new quote-balance validation behavior. |
github-code-search.ts |
Calls the validator early and exits with a user-facing error message on failure. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Plain-text (non-regex) queries with an odd number of unescaped double quotes were sent straight to the GitHub API, which rejects them with an opaque 422 ERROR_TYPE_QUERY_PARSING_FATAL. validateQuoteBalance() now detects this locally before any network call and exits with an actionable message, including a corrected example using GitHub's documented double-escaping syntax (shell + GitHub). Balanced-quote queries (including legitimate exact-phrase queries like "feature flag") and regex /pattern/ queries are unaffected — the latter are already validated separately by buildApiQuery/extractApiTerm. Closes #149
af9a0ca to
aae0acb
Compare
|
Coverage after merging fix/plain-text-quote-validation into fix/regex-api-term-quotes will be
Coverage Report
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1 similar comment
|
Coverage after merging fix/plain-text-quote-validation into fix/regex-api-term-quotes will be
Coverage Report
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
…le query Addresses Copilot review feedback: validateQuoteBalance() previously returned null for any query containing a /pattern/ regex token (via isRegexQuery), skipping validation for everything else in the query. A mixed query like 'filename:package.json /regex/ "oops' could still reach the GitHub API with an unbalanced stray quote outside the token, hitting the same opaque 422 ERROR_TYPE_QUERY_PARSING_FATAL issue #149 was meant to prevent entirely. Now only the /pattern/ token itself is excluded from the quote-balance check (its quotes are handled separately by buildApiQuery/extractApiTerm), while the rest of the query (qualifiers, free text) is still validated. See #153 (comment)
|
Coverage after merging fix/plain-text-quote-validation into fix/regex-api-term-quotes will be
Coverage Report
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
What does this PR do?
Closes #149.
Plain-text (non-regex) queries with raw double quotes could silently produce false positives (GitHub strips balanced quotes and treats adjacent punctuation as separate terms) or an opaque
422 ERROR_TYPE_QUERY_PARSING_FATALfrom the API when the quote count was odd.validateQuoteBalance()insrc/regex.tsnow detects an odd number of unescaped double quotes in a plain-text query before any network call, andgithub-code-search.tsexits early with an actionable message that includes a corrected example using GitHub's documented double-escaping syntax (shell and GitHub). Regex/pattern/queries are unaffected, they are validated separately bybuildApiQuery/extractApiTerm(see #147). Balanced-quote queries, including legitimate exact-phrase queries like"feature flag", keep working unchanged.How did you verify your code works?
src/regex.test.tscovering balanced, unbalanced, escaped, and regex-bypass cases.