Skip to content

fix: reject an unknown field name in search text_fields#3

Merged
federico-martinez-invgate merged 1 commit into
mainfrom
fix/reject-unknown-search-fields
Jul 10, 2026
Merged

fix: reject an unknown field name in search text_fields#3
federico-martinez-invgate merged 1 commit into
mainfrom
fix/reject-unknown-search-fields

Conversation

@federico-martinez-invgate

Copy link
Copy Markdown
Contributor

search() silently skipped any text_fields entry not present in the schema (Err(_) => continue), so a typo like text_fields:["titel"] produced no text clause and returned {"hits":[]} -- indistinguishable from a legitimately empty result and invisible in production. It was also inconsistent with the where/in sections of the same function, which already error on an unknown field.

Resolve text_fields up front, once, before the per-word loop: an unknown named field now returns a clear error ("campo text_fields '' no existe"), matching the where/in style. A legitimately empty text_fields list stays a no-op, and a genuinely empty query still returns []. The up-front pass also validates even when text is empty (the previous lazy resolution never ran with zero tokens) and removes the redundant per-token get_field.

Reconcile the ClientInterface docblock: an unknown top-level query key is ignored (serde drops it), but a named field absent from the schema is a hard error.

Tests: rejects_unknown_text_field reproduces the silent-empty bug and now asserts the exact error; valid_text_field_still_matches and empty_query_still_returns_empty guard against over-reach. Validated against the real Service Desk search path (text_fields is always getIndexes(), a subset of the index's declared text fields -- no call-site passes an undeclared name).

search() silently skipped any text_fields entry not present in the schema
(Err(_) => continue), so a typo like text_fields:["titel"] produced no text
clause and returned {"hits":[]} -- indistinguishable from a legitimately empty
result and invisible in production. It was also inconsistent with the where/in
sections of the same function, which already error on an unknown field.

Resolve text_fields up front, once, before the per-word loop: an unknown named
field now returns a clear error ("campo text_fields '<name>' no existe"),
matching the where/in style. A legitimately empty text_fields list stays a
no-op, and a genuinely empty query still returns []. The up-front pass also
validates even when text is empty (the previous lazy resolution never ran with
zero tokens) and removes the redundant per-token get_field.

Reconcile the ClientInterface docblock: an unknown top-level query key is
ignored (serde drops it), but a named field absent from the schema is a hard
error.

Tests: rejects_unknown_text_field reproduces the silent-empty bug and now
asserts the exact error; valid_text_field_still_matches and
empty_query_still_returns_empty guard against over-reach. Validated against the
real Service Desk search path (text_fields is always getIndexes(), a subset of
the index's declared text fields -- no call-site passes an undeclared name).
@federico-martinez-invgate federico-martinez-invgate merged commit 3433b7d into main Jul 10, 2026
12 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant