Skip to content

Fix in_(): quote string values to handle colons in Solr identifiers#141

Merged
tomkralidis merged 1 commit into
geopython:mainfrom
epifanio:fix/solr-backend-bugs
May 26, 2026
Merged

Fix in_(): quote string values to handle colons in Solr identifiers#141
tomkralidis merged 1 commit into
geopython:mainfrom
epifanio:fix/solr-backend-bugs

Conversation

@epifanio

Copy link
Copy Markdown
Contributor

Problem

in_() interpolates option values bare into the Solr query string:

field:(value1 OR value2)

This breaks silently when any value contains a colon. Solr's query parser
treats a bare colon as a field separator, so an identifier like
no.met.adc:fe10e5c9-a226-58be-829e-cfe5c3a3fc45 is parsed as field no.met.adc
with value fe10e5c9-..., which either silently matches the wrong field or raises
a Solr parse error (undefined field no.met.adc).

This is the same class of bug already fixed in equality() — that fix wraps
the RHS string in double quotes. in_() was missed.

Real-world case: STAC POST /search with an ids or collections filter
containing namespaced identifiers (common in OGC/ISO metadata catalogues that use
authority:uuid or scheme:localid conventions).

Fix

Wrap each string option in double quotes, escaping any embedded double quotes.
Numeric values are left unchanged.

def _quote(v):
    if isinstance(v, str):
        return '"' + v.replace('"', '\\"') + '"'
    return str(v)
options_str = " OR ".join(_quote(option) for option in options)

Produces:

field:("value1" OR "no.met.adc:fe10e5c9-...")

which Solr parses correctly as phrase/term queries.

Context

Found while testing the MET Norway pycsw Solr plugin against a live STAC API
endpoint. Collection and item identifiers follow the authority:uuid pattern
throughout the ADC/NBS/GCW Arctic metadata catalogues.

The companion fix in equality() (already in main) uses the same quoting
approach for single-value equality comparisons; this PR extends it to
multi-value IN filters for consistency.

gh pr create
--repo geopython/pygeofilter
--base main
--head epifanio:fix/solr-backend-bugs
--title "Fix in_(): quote string values to handle colons and special characters in Solr identifiers"
--body-file /tmp/pygeofilter_pr_body.md 2>&1

…fiers

String values passed to an IN filter were interpolated bare into the Solr
query string:

    field:(value1 OR value2)

This breaks silently when any value contains a colon, e.g. a namespaced
identifier like `no.met.adc:fe10e5c9-a226-...`. Solr's query parser treats
the colon as a field separator, so `no.met.adc:fe10e5c9-...` becomes a
query on field `no.met.adc` with value `fe10e5c9-...`, which either matches
the wrong field or raises a syntax error.

Fix: wrap each string option in double quotes (escaping any embedded quotes),
producing:

    field:("value1" OR "value2")

Numeric values are left unchanged (str(v) with no quotes).

This mirrors the quoting already applied in equality() for the same reason.
@tomkralidis tomkralidis merged commit a7893b5 into geopython:main May 26, 2026
5 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.

2 participants