Skip to content

[NAE-2470] - PFQL double quote string support - #468

Open
mazarijuraj wants to merge 1 commit into
release/6.6.0from
NAE-2470
Open

[NAE-2470] - PFQL double quote string support#468
mazarijuraj wants to merge 1 commit into
release/6.6.0from
NAE-2470

Conversation

@mazarijuraj

@mazarijuraj mazarijuraj commented Jul 31, 2026

Copy link
Copy Markdown
Contributor

Description

Implements NAE-2470

  • update PFQL grammar to support double quote strings
  • add new queries to QueryLangTest.java
  • update SearchUtils to support double quote strings

How Has Been This Tested?

Manually and also adding new queries to existing PFQL test

Checklist:

  • [*] My code follows the style guidelines of this project
  • [*] I have performed a self-review of my own code
  • My changes have been checked, personally or remotely, with @...
  • I have commented my code, particularly in hard-to-understand areas
  • I have resolved all conflicts with the target branch of the PR
  • I have updated and synced my code with the target branch
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing tests pass locally with my changes:
    • Lint test
    • [*] Unit tests
    • Integration tests
  • I have checked my contribution with code analysis tools:
  • I have made corresponding changes to the documentation:
    • Developer documentation
    • User Guides
    • Migration Guides

Summary by CodeRabbit

  • New Features

    • Added support for single- and double-quoted text values in PFQL queries.
    • Escaped characters are supported within quoted values.
  • Bug Fixes

    • Improved handling of quoted search values by removing only matching surrounding quotes.
    • Preserved quote characters within search text.

- update PFQL grammar to support double quote strings
- add new queries to QueryLangTest.java
- update SearchUtils to support double quote strings
@mazarijuraj
mazarijuraj requested review from Kovy95 and Retoocs July 31, 2026 09:08
@mazarijuraj mazarijuraj self-assigned this Jul 31, 2026
@coderabbitai

coderabbitai Bot commented Jul 31, 2026

Copy link
Copy Markdown

Review Change Stack

Walkthrough

PFQL now supports single- and double-quoted string literals with escapes. String normalization removes only matching outer quotes. Tests cover double-quoted and mixed-quote process and case queries.

Changes

PFQL quoted string support

Layer / File(s) Summary
Quoted string parsing and normalization
src/main/java/com/netgrif/application/engine/pfql/domain/antlr4/QueryLang.g4, src/main/java/com/netgrif/application/engine/pfql/service/utils/SearchUtils.java
The grammar accepts escaped single- and double-quoted strings. getStringValue removes only matching outer quotes and preserves internal quotes.
Quoted query coverage
src/test/java/com/netgrif/application/engine/pfql/QueryLangTest.java
Tests cover double-quoted process queries and mixed quote styles in case predicates. Assertions verify result types, counts, titles, and field values.

Estimated code review effort: 2 (Simple) | ~10 minutes

Possibly related PRs

Suggested labels: improvement, Medium

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely identifies the main change: support for double-quoted strings in PFQL.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot added improvement A change that improves on an existing feature Medium labels Jul 31, 2026

@coderabbitai coderabbitai Bot 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.

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In
`@src/main/java/com/netgrif/application/engine/pfql/service/utils/SearchUtils.java`:
- Line 183: Update SearchUtils.getStringValue() to decode the escape sequences
accepted by QueryLang.g4 after removing the surrounding quote delimiters, so
escaped quotes and backslashes reach predicate evaluation as their literal
characters. Preserve unescaped string handling and add an end-to-end regression
test covering escaped quotes and backslash escapes.
- Line 183: Update the quote-stripping logic in SearchUtils to remove exactly
one outer pair only when the first and last characters are matching single or
double quotes. Preserve all remaining quote characters, including repeated or
mismatched boundary quotes, instead of using a regex that removes consecutive
delimiters.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: feda0337-32bc-48e0-9c5e-3e5d9a2a7306

📥 Commits

Reviewing files that changed from the base of the PR and between 03f4e73 and be576d3.

📒 Files selected for processing (3)
  • src/main/java/com/netgrif/application/engine/pfql/domain/antlr4/QueryLang.g4
  • src/main/java/com/netgrif/application/engine/pfql/service/utils/SearchUtils.java
  • src/test/java/com/netgrif/application/engine/pfql/QueryLangTest.java


public static String getStringValue(String queryLangString) {
return queryLangString.replace("'", "");
return queryLangString.replaceAll("^[\"']+|[\"']+$", "");

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🎯 Functional Correctness | 🟠 Major | ⚡ Quick win

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
set -euo pipefail

echo "== locate files =="
fd -a 'SearchUtils.java|QueryLang.g4|QueryLangEvaluator.java' . | sed 's#^\./##'

echo
echo "== SearchUtils relevant section =="
file=$(fd 'SearchUtils.java' . | head -n 1)
if [ -n "$file" ]; then
  wc -l "$file"
  sed -n '130,210p' "$file" | cat -n
fi

echo
echo "== QueryLang parser/evaluator relevant sections =="
for f in $(fd 'QueryLang.g4|QueryLangEvaluator.java' .); do
  echo "--- $f"
  wc -l "$f"
  sed -n '320,360p' "$f" | cat +n
  sed -n '120,175p' "$f" | cat +n
done

echo
echo "== search for STRING literal handling / eval methods =="
rg -n "getString|QueryLangString|QueryLang|STRING|Escape|replaceAll|O\\\\'|\\\\\\'" src/main || true

echo
echo "== read-only deterministic probe: Java source literal token value extraction would be needed; inspect whether any unescape helper exists =="
rg -n "parse.*String|unescape|\\\\\\\\|replaceFirst|QueryLangString" src/main/java/com/netgrif/application/engine/pfql || true

Repository: netgrif/application-engine

Length of output: 4771


🏁 Script executed:

#!/bin/bash
set -euo pipefail

echo "== QueryLang.g4 string tokens =="
sed -n '320,360p' src/main/java/com/netgrif/application/engine/pfql/domain/antlr4/QueryLang.g4

echo
echo "== QueryLang.g4 parse/string rule annotations =="
rg -n "(@|STRING|queryLangString|EscapedCharacter)" src/main/java/com/netgrif/application/engine/pfql/domain/antlr4/QueryLang.g4

echo
echo "== QueryLangEvaluator string handling =="
sed -n '120,175p' src/main/java/com/netgrif/application/engine/pfql/service/QueryLangEvaluator.java

echo
echo "== SearchUtils predicate builders using getStringValue =="
rg -n "getStringValue\\(" src/main/java/com/netgrif/application/engine/pfql/service/utils/SearchUtils.java -A 8 -B 8

echo
echo "== unescape/substring literals and helper usages =="
rg -n "queryString|queryLangString|getStringValue|getString\\(|unescape|replaceFirst\\(\"^[\"']|\"\"\\)|\"\\\\\\\\\"" src/main/java/com/netgrif/application/engine/pfql/service src/main/java/com/netgrif/application/engine/pfql/domain/antlr4 -C 3

echo
echo "== read-only behavioral probe: Java lexer token text model for escaped string =="
python3 - <<'PY'
import re
text = r"['O\\'Reilly'\""
# Simulate Java-style source-text tokenization where escaped quotes are part of the token text.
# This does not execute Java code; it checks whether stripping delimiters alone leaves backslash.
s = "O\\'Reilly"
stripped = re.sub(r"^[\"']+|[\"']+$", "", "'" + s + "'")
print("lexer_token_text:", "'" + s + "'")
print("getStringValue_result:", stripped)
print("contains_backslash:", "\\" in stripped)
print("expected_after_decode_Java:", r"O'Reilly")
PY

Repository: netgrif/application-engine

Length of output: 44866


Decode STRING escape sequences before predicate construction.

QueryLang.g4 accepts escaped characters in STRING literals, but SearchUtils.getStringValue() only strips delimiters at src/main/java/com/netgrif/application/engine/pfql/service/utils/SearchUtils.java:182-183. This makes valid queries like 'O\'Reilly' reach the evaluator as O\'Reilly instead of O'Reilly. Decode escaped characters when extracting literal values, or narrow the lexer rule and call sites so that backslashes are not valid in string payloads. Add an end-to-end regression test for escaped quotes and backslash escapes.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In
`@src/main/java/com/netgrif/application/engine/pfql/service/utils/SearchUtils.java`
at line 183, Update SearchUtils.getStringValue() to decode the escape sequences
accepted by QueryLang.g4 after removing the surrounding quote delimiters, so
escaped quotes and backslashes reach predicate evaluation as their literal
characters. Preserve unescaped string handling and add an end-to-end regression
test covering escaped quotes and backslash escapes.

🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win

Remove only the matching outer quote pair.

Line 183 removes every consecutive ' or " character at each boundary. It can remove quote characters that belong to the value. The valid PFQL literal '"foo"' becomes foo, not "foo".

Check the first and last characters and remove exactly one matching pair.

Proposed delimiter fix
-        return queryLangString.replaceAll("^[\"']+|[\"']+$", "");
+        if (queryLangString.length() < 2) {
+            return queryLangString;
+        }
+        char delimiter = queryLangString.charAt(0);
+        if ((delimiter != '\'' && delimiter != '"')
+                || queryLangString.charAt(queryLangString.length() - 1) != delimiter) {
+            return queryLangString;
+        }
+        return queryLangString.substring(1, queryLangString.length() - 1);
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
return queryLangString.replaceAll("^[\"']+|[\"']+$", "");
if (queryLangString.length() < 2) {
return queryLangString;
}
char delimiter = queryLangString.charAt(0);
if ((delimiter != '\'' && delimiter != '"')
|| queryLangString.charAt(queryLangString.length() - 1) != delimiter) {
return queryLangString;
}
return queryLangString.substring(1, queryLangString.length() - 1);
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In
`@src/main/java/com/netgrif/application/engine/pfql/service/utils/SearchUtils.java`
at line 183, Update the quote-stripping logic in SearchUtils to remove exactly
one outer pair only when the first and last characters are matching single or
double quotes. Preserve all remaining quote characters, including repeated or
mismatched boundary quotes, instead of using a regex that removes consecutive
delimiters.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

improvement A change that improves on an existing feature Medium

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants