Skip to content

Support doubled quotes in KQL values - #3858

Merged
aduffeck merged 2 commits into
opencloud-eu:mainfrom
aduffeck:kql-quote-escaping
Nov 2, 2026
Merged

aduffeck merged 2 commits into
opencloud-eu:mainfrom
aduffeck:kql-quote-escaping

Conversation

@aduffeck

@aduffeck aduffeck commented Oct 29, 2026 •

Copy link
Copy Markdown
Member

Fixes #3666

@AlexAndBear jfyi. With this change you can do queries like

curl -k -u admin:admin -X REPORT https://localhost:9200/remote.php/dav/spaces/ \
  -H 'Content-Type: application/xml' --data-binary @- <<'EOF'
<?xml version="1.0" encoding="UTF-8"?>
<oc:search-files xmlns:a="DAV:" xmlns:oc="http://owncloud.org/ns">
  <oc:search>
    <oc:pattern>name:"*""quoted""*"</oc:pattern>
    <oc:limit>50</oc:limit>
  </oc:search>
</oc:search-files>
EOF

to query for strings cotaining quotes.

@codacy-production

codacy-production Bot commented Oct 29, 2026 •

Copy link
Copy Markdown

Up to standards ✅

🟢 Issues 0 issues

Results:
0 new issues

View in Codacy

🟢 Metrics 8 complexity

Metric Results
Complexity 8

View in Codacy

🟢 Coverage 88.02% diff coverage

Metric Results
Coverage variation Report missing for 5d745311
Diff coverage ✅ 88.02% diff coverage

View coverage diff in Codacy

Coverage variation details
Coverable lines Covered lines Coverage
Common ancestor commit (5d74531) Report Missing Report Missing Report Missing
Head commit (ff74224) 93253 25925 27.80%

Coverage variation is the difference between the coverage for the head and common ancestor commits of the pull request branch: <coverage of head commit> - <coverage of common ancestor commit>

Diff coverage details
Coverable lines Covered lines Diff coverage
Pull request (#3858) 1010 889 88.02%

Diff coverage is the percentage of lines that are covered by tests out of the coverable lines that the pull request added or modified: <covered lines added or modified>/<coverable lines added or modified> * 100%

1 Codacy didn't receive coverage data for the commit, or there was an error processing the received data. Check your integration for errors and validate that your coverage setup is correct.

NEW Get contextual insights on your PRs based on Codacy's metrics, along with PR and Jira context, without leaving GitHub. Enable AI reviewer
TIP This summary will be updated as you push new changes.

@AlexAndBear

Copy link
Copy Markdown
Member

Great, thanks!

@rhafer rhafer left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot found a bit of a corner case, where I am not sure what the correct behavior is:

There is a conflict between the new quoted-string rule and the existing date rule in pkg/kql/dictionary.peg.
For example:
name:"2024-01-01""foo"""
Under the PR’s quoting rules, this is one value: 2024-01-01"foo". But DateTimeRestrictionNode is tried before TextPropertyRestrictionNode. It consumes name:"2024-01-01" as a date restriction, treating the first quote of the doubled pair as the closing quote. The remainder, "foo""", becomes a separate free-text value, foo".
I verified that the builder accepts the query and produces those two nodes with an implicit AND, rather than one string node. The backends then receive the wrong query: OpenSearch rejects the : date operator, while Bleve skips that date node.
The date-rule precedence predates this PR, but it conflicts with the newly supported doubled-quote syntax.

@aduffeck

Copy link
Copy Markdown
Member Author

Great catch 🤣
It went further than the doubled-quote case: the date and number rules took an optional quote on each side, independently, and never checked where the value ended. Since they run before the text rule, they grabbed any prefix that happened to parse, quoted or not. The boolean rule had the same problem.

I changed it so a value only counts as a date, number or boolean when it is the whole value: either in balanced quotes with the closing quote not followed by another ", or unquoted and followed by a space, a parenthesis, a quote or the end of the query. Everything else falls through to the text rule.

Query Before After
name:"2024-01-01""foo""" date AND foo" text 2024-01-01"foo"
name:todays_report date today AND s_report text todays_report
name:trueish bool true AND ish text trueish
name:2024-01-01foo date AND foo text 2024-01-01foo
Modified:"2023-09-05 date (quote left open) validation error

All existing date, number and boolean forms parse as before. An unclosed quote on a typed value is now rejected, the same as for text values.

@aduffeck
aduffeck merged commit 12d8edb into opencloud-eu:main Nov 2, 2026
60 checks passed
@aduffeck
aduffeck deleted the kql-quote-escaping branch November 2, 2026 07:56
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.

KQL search can't escape quotes, a trailing backslash causes a 500

3 participants