Skip to content

fix(query): handle semicolons inside string literals#131

Merged
ErikBjare merged 1 commit intoActivityWatch:masterfrom
TimeToBuildBob:bob/fix-query-semicolon
Feb 27, 2026
Merged

fix(query): handle semicolons inside string literals#131
ErikBjare merged 1 commit intoActivityWatch:masterfrom
TimeToBuildBob:bob/fix-query-semicolon

Conversation

@TimeToBuildBob
Copy link
Contributor

@TimeToBuildBob TimeToBuildBob commented Feb 27, 2026

Summary

Fixes ActivityWatch/aw-server#145.

The query parser was using query.split(';') to separate statements, which incorrectly split on semicolons inside string literals, causing QueryParseException for valid queries like:

RETURN = "hello;world"

Root Cause

In aw_query/query2.py, the query() function did:

query_stmts = query.split(";")

This splits on all semicolons, including those inside string literals. The rest of the parser correctly handles string tokenization (see QString.check()), but statement splitting happened before tokenization.

Fix

Replace query.split(";") with a new _split_query_statements() function that tracks quote state (single/double) and only splits on semicolons that are actual statement terminators — not those inside string literals.

Tests

Added:

  • test_query2_semicolon_in_string — end-to-end query tests with semicolons in strings
  • test_split_query_statements — unit tests for the new splitter function

All 29 existing tests continue to pass.


Important

Fixes query parsing to handle semicolons inside string literals by replacing split with a custom function in query2.py.

  • Behavior:
    • Replaces query.split(";") with _split_query_statements() in query() in query2.py to correctly handle semicolons inside string literals.
    • _split_query_statements() tracks quote state to avoid splitting within string literals.
  • Tests:
    • Adds test_query2_semicolon_in_string for end-to-end testing of semicolons in strings.
    • Adds test_split_query_statements for unit testing the new splitting function.
    • All 29 existing tests continue to pass.

This description was created by Ellipsis for 66a8d55. You can customize this summary. It will automatically update as commits are pushed.

The query parser was using query.split(';') to separate statements,
which incorrectly split on semicolons inside string literals, causing
QueryParseException for valid queries like 'RETURN = "hello;world"'.

Replace with _split_query_statements() that tracks quote state and
only splits on semicolons that are actual statement terminators.

Fixes ActivityWatch/aw-server#145
Copy link

@ellipsis-dev ellipsis-dev bot left a comment

Choose a reason for hiding this comment

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

Important

Looks good to me! 👍

Reviewed everything up to 66a8d55 in 19 seconds. Click for details.
  • Reviewed 101 lines of code in 2 files
  • Skipped 0 files when reviewing.
  • Skipped posting 0 draft comments. View those below.
  • Modify your settings and rules to customize what types of comments Ellipsis leaves. And don't forget to react with 👍 or 👎 to teach Ellipsis.

Workflow ID: wflow_GAPARiHB1JtmEPPa

You can customize Ellipsis by changing your verbosity settings, reacting with 👍 or 👎, replying to comments, or adding code review rules.

@greptile-apps
Copy link

greptile-apps bot commented Feb 27, 2026

Greptile Summary

This PR fixes a bug where semicolons inside string literals caused the query parser to incorrectly split statements. The fix replaces the naive query.split(';') with a new _split_query_statements() function that tracks quote state and only splits on semicolons outside string literals.

Key Changes:

  • Added _split_query_statements() function that respects string boundaries when splitting on semicolons
  • Implementation uses the same escape handling pattern (prev_char != "\\") as existing tokenizers (QString.check(), QFunction.check(), etc.)
  • Comprehensive test coverage with both unit tests and end-to-end query execution tests

Testing:

  • Tests cover double quotes, single quotes, multiple statements, and trailing semicolons
  • All 29 existing tests continue to pass
  • No breaking changes to the query language syntax

Confidence Score: 5/5

  • This PR is safe to merge with minimal risk
  • The fix is well-implemented, consistent with existing codebase patterns, has comprehensive test coverage, and all existing tests pass. The change is focused and addresses a specific bug without introducing breaking changes.
  • No files require special attention

Important Files Changed

Filename Overview
aw_query/query2.py Added _split_query_statements() function that correctly handles semicolons inside string literals by tracking quote state, replacing naive query.split(';'). Implementation is consistent with existing quote-handling logic throughout the codebase.
tests/test_query2.py Added comprehensive tests for semicolon handling in string literals, including both unit tests for the splitter function and end-to-end query execution tests with single/double quotes and multiple statements.

Last reviewed commit: 66a8d55

Copy link

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

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

2 files reviewed, no comments

Edit Code Review Agent Settings | Greptile

@ErikBjare ErikBjare merged commit d628a9a into ActivityWatch:master Feb 27, 2026
4 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.

QueryParseException when semicolon in expression

2 participants