Skip to content

Escape only what iTop's OQL lexer accepts in quoteString() - #26

Open
agent-qv wants to merge 1 commit into
Combodo:masterfrom
agent-qv:pr/quotestring-oql-lexer
Open

agent-qv wants to merge 1 commit into
Combodo:masterfrom
agent-qv:pr/quotestring-oql-lexer

Conversation

@agent-qv

@agent-qv agent-qv commented Oct 19, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #25.

quoteString() now escapes only ' and \, the two escape sequences iTop's OQL lexer accepts inside a quoted literal. The JSON layer needs nothing from this method: the .json.twig templates are rendered with Twig's js escaping strategy.

If escaping _ and % was meant to keep them from acting as LIKE wildcards: the tools using quoteString() compare with =, where both are plain characters, and iTop's lexer offers no way to escape them inside a literal anyway, so a value containing them could not be looked up at all.

The tests check the property itself: once quoted and wrapped in single quotes, a value must match the lexer's literal pattern, and stripslashes() must give it back unchanged.

Inside a quoted OQL literal, iTop's lexer accepts exactly two escape
sequences, \' and \\ (the 'strval' rule of core/oql/oql-lexer.plex), and
its parser unescapes the literal with stripslashes(). quoteString() also
emitted \_ \% \" \n \r \t \0 \Z \b, MySQL's real_escape_string set, and
the lexer rejects every one of them: a value containing any of those
characters turns the query into an OQL syntax error. In practice,
get-person-from-email fails for any address containing an underscore,
such as john_doe@example.com.

The JSON layer needs nothing from this method: the .json.twig templates
are rendered with Twig's 'js' escaping strategy, which already produces
valid JSON whatever the value.

The tests now check the property itself: once quoted and wrapped in
single quotes, a value must match the lexer's literal pattern, and
stripslashes() must give it back unchanged.
Copilot AI balanced review requested due to automatic review settings October 19, 2026 08:58

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟢 Approval recommended

The focused fix matches the OQL literal contract and includes relevant regression coverage, with no unresolved findings.

No open issues 🎉

What changed in this PR

Fixes OQL query failures for values such as email addresses containing underscores by limiting quoteString() to supported escapes.

Changes:

  • Escapes only apostrophes and backslashes.
  • Adds regression tests for valid OQL literals and unchanged round-trip values.
File Description
tests/​phpunit/​ToolsFromTemplateTest.php Updates escaping expectations and adds literal validation tests.
src/​Tools/​iTopRestTools.php Removes unsupported escapes and documents the OQL/JSON boundary.

Review effort: Balanced

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.

quoteString() escapes characters that iTop's OQL lexer rejects: lookups fail for an email containing an underscore

2 participants