fix(queries): don't split on semicolons inside string literals - #918
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #918 +/- ##
==========================================
+ Coverage 38.11% 38.63% +0.51%
==========================================
Files 42 42
Lines 2259 2278 +19
Branches 428 435 +7
==========================================
+ Hits 861 880 +19
Misses 1377 1377
Partials 21 21 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Greptile SummaryThe PR introduces quote-aware AQL statement splitting and routes all previously identified view-level query paths through the shared helper.
Confidence Score: 5/5The query-splitting fix appears safe to merge. No blocking failure remains in the previously reported view-level query-splitting paths. Important Files Changed
Reviews (2): Last reviewed commit: "fix(views): use querystr_to_array in all..." | Re-trigger Greptile |
aafe7dc to
e42479b
Compare
|
CI flags two lint warnings (treated as errors with
Greptile also flagged a P1 (confidence 3/5): view-level query execution paths apparently still call |
|
Both issues are now fixed and pushed. Lint (now passing):
View-level scope (Greptile P1 addressed):
CI is running on the updated branch. |
|
@greptileai review |
querystr_to_array() was naively splitting on all ';' characters, which
shredded category rules whose regex contained a semicolon. For example,
a rule with regex "foo;bar" gets embedded into the query as:
events = categorize(events, [["Work", {"type":"regex","regex":"foo;bar"}]]);
A plain .split(';') would cut this into two broken fragments before the
query ever reaches aw-server, causing a parse error on the server side.
Both aw-server-python and aw-server-rust handle semicolons correctly
inside quoted strings — the bug is purely in the client-side splitter.
The fix tracks string-literal context (double-quoted, with backslash
escape support) and only treats ';' as a statement separator when it
appears outside a string.
Also exports querystr_to_array for direct unit testing and adds 4 unit
tests covering: basic split, semicolon-in-string (the regression case),
escaped quote handling, and whitespace filtering.
Closes ActivityWatch#724 (the right fix is here, not a UI warning/block).
…tier - `escape` is a reserved JS global; rename to `inEscape` to silence no-shadow - collapse two-line const assignment in test to satisfy prettier line-length rule
Seven views were still doing a naive .split(';') on query strings before
sending them to aw-client. Category rules with semicolons in their regex
(e.g. "foo;bar") embed as JSON string literals inside the AQL query, so a
plain split shreds them before they reach the server.
Replace every .split(';').map(s => s.trim() + ';') chain (and the two
longer filter-variant chains in Timeline and Trends) with querystr_to_array,
which correctly skips semicolons inside double-quoted string literals.
557161e to
96d2096
Compare
|
CI-green and mergeable (Greptile 5/5) — waiting only on a maintainer click. This PR is ready to merge, but the bot has pull-only access to this repo and can't self-merge — surfacing it here so it isn't lost. The monitoring loop will stop re-flagging it now that this note is posted. |
Root cause
querystr_to_array()naively splits on all;characters. Category rules get embedded as JSON string literals inside the query — for example a rule with regexfoo;barbecomes:A plain
.split(';')shreds this into two broken fragments before the query reaches aw-server, causing a parse error. Both aw-server-python and aw-server-rust handle;inside quoted string literals correctly — the bug is entirely in the client-side splitter.This explains the forum report in #724 and why the UI warning (PR #724) was only a workaround.
Fix
src/queries.tsThe new
querystr_to_arraytracks double-quoted string context (with backslash-escape support) and only treats;as a statement separator when it appears outside a string literal.Also exports
querystr_to_arrayfor direct unit testing and adds 4 tests:View files (7 updated)
All view-level query splitting paths now use
querystr_to_arrayinstead of a naive.split(';'):views/Alerts.vue,views/Search.vue,views/Graph.vue,views/Report.vue,views/QueryExplorer.vue— replace.split(';').map(s => s.trim() + ';')views/Timeline.vue,views/Trends.vue— replace the longer split/trim/filter/map chainInvestigation notes (from #724 comment thread)
Checked aw-server-rust's lexer (
aw-query/src/lexer.rs): the string-literal rule"([^\"]|(\\\"))*"is matched before the bare;→Token::Semirule, so semicolons inside quoted strings are correctly captured as part ofToken::String. The server is not the problem.Fixes #724.