Skip to content

Commit dab42e4

Browse files
docs(code-search): explain explicit AND queries (#1015)
1 parent 56f9813 commit dab42e4

2 files changed

Lines changed: 13 additions & 4 deletions

File tree

‎comfy_cli/command/code_search.py‎

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,8 @@
4747
# `timeout: 30` (a YAML-ish literal) are not rejected — a real Sourcegraph
4848
# filter value is never separated from its colon by whitespace.
4949
_INJECTED_FILTER_RE = re.compile(
50-
r"(^|[\s(])-?(count|repo|r|timeout|context|rev|revision|fork|archived|select):(?=[^\s)])", re.IGNORECASE
50+
r"(^|[\s(])-?(count|repo|r|timeout|context|rev|revision|fork|archived|select|patterntype):(?=[^\s)])",
51+
re.IGNORECASE,
5152
)
5253

5354
# C0 (0x00-0x1F) and C1 (0x7F-0x9F) control characters, including ESC (0x1B)
@@ -106,8 +107,8 @@ def _validate_query(query: str, repo: str | None) -> None:
106107
raise ValueError(f"query must be at most {MAX_QUERY_BYTES} bytes")
107108
if _INJECTED_FILTER_RE.search(query):
108109
raise ValueError(
109-
"query must not contain count:, repo:, timeout:, context:, rev:, revision:, fork:, archived:, or "
110-
"select: filters"
110+
"query must not contain count:, repo:, timeout:, context:, rev:, revision:, fork:, archived:, "
111+
"select:, or patterntype: filters"
111112
)
112113
if repo and re.search(r"\s", repo):
113114
raise ValueError("repo must not contain whitespace")
@@ -475,7 +476,12 @@ def code_search(
475476
typer.Argument(
476477
help=(
477478
"Search query (supports Sourcegraph syntax). Defaults to file matches; "
478-
"pass your own `type:` filter (e.g. `type:commit`) to override."
479+
"pass your own `type:` filter (e.g. `type:commit`) to override. Whitespace is "
480+
"not a reliable AND: whether `seedWidget serializeValue` matches both terms or "
481+
"one literal phrase depends on the service's pattern-type default, which this "
482+
"command does not pin. Join multiple concepts with explicit `AND` instead "
483+
"(`seedWidget AND serializeValue`) to get the same result regardless of that "
484+
"default."
479485
),
480486
),
481487
],

‎tests/comfy_cli/command/test_code_search.py‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,7 @@ def test_rejects_injected_filters_and_repo_whitespace(self):
184184
"fork:yes x",
185185
"archived:yes x",
186186
"select:repo x",
187+
"patterntype:regexp x",
187188
):
188189
with pytest.raises(ValueError):
189190
_validate_query(query, None)
@@ -208,11 +209,13 @@ def test_rejects_grouped_and_aliased_repo_filters(self):
208209
"foo OR (fork:yes)",
209210
"foo OR (archived:yes)",
210211
"foo OR (select:repo)",
212+
"foo OR (patterntype:regexp)",
211213
"foo -context:evil",
212214
"foo -rev:evil",
213215
"foo -fork:yes",
214216
"foo -archived:yes",
215217
"foo -select:repo",
218+
"foo -patterntype:regexp",
216219
):
217220
with pytest.raises(ValueError):
218221
_validate_query(query, None)

0 commit comments

Comments
 (0)