Skip to content

Conversation

@lucasnetau
Copy link
Contributor

@lucasnetau lucasnetau commented Mar 24, 2025

🔀 Pull Request

What does this PR do?

White space after the comparator value was consumed by the regex leading to invalid decoding of strings surrounded by single quotes.

This adds the optional whitespace to the positive lookahead. Additionally the lookahead match group is made non-capturing as it serves no purpose in further processing.

Test Plan

An additional test testQueryMatchWhitespaceIgnored was added to tests/JSONPathTest.php which has a filter string with deliberate additional whitespace added around the query.

Related PRs and Issues

I did not open an issue ticket for this issue.

Summary by CodeRabbit

  • Bug Fixes

    • Filter expressions now handle additional whitespace around logical operators more effectively, ensuring more reliable and accurate query results.
  • Documentation

    • Internal release notes have been updated to version 0.10.1.
  • Tests

    • Added automated tests to confirm that filters correctly process expressions with extra spacing.

@coderabbitai
Copy link

coderabbitai bot commented Mar 24, 2025

Walkthrough

The update introduces version 0.10.1 in the changelog, which documents a fix for whitespace handling in filter expressions. A regular expression in the QueryMatchFilter class has been modified to allow whitespace before logical operators. Additionally, a new test method has been added to validate this behavior in the JSONPath library.

Changes

File(s) Change Summary
CHANGELOG.md Added version 0.10.1 entry documenting a fix for whitespace handling in filter expressions.
src/Filters/QueryMatchFilter.php Modified regex in QueryMatchFilter to allow whitespace before logical operators.
tests/JSONPathTest.php Added test method testQueryMatchWhitespaceIgnored to validate JSONPath handling of whitespace in filter strings.

Sequence Diagram(s)

sequenceDiagram
    participant TestCase as JSONPathTest
    participant JSONPathLib as JSONPath Library
    participant Filter as QueryMatchFilter
    participant Regex as Regex Engine

    TestCase->>JSONPathLib: Execute query with extra whitespace
    JSONPathLib->>Filter: Process filter expression
    Filter->>Regex: Evaluate regex with updated lookahead
    Regex-->>Filter: Return match result
    Filter-->>JSONPathLib: Return filtered data
    JSONPathLib-->>TestCase: Provide query output
Loading

Poem

I'm a rabbit with ears so keen,
Hoping through code in soft moonbeam.
Whitespace now dances with grace,
Logical operators find their place.
Version 0.10.1 makes me cheer—
Carrots and code, the best of the year!
🥕🐇


🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@codecov-commenter
Copy link

codecov-commenter commented Mar 24, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 89.86%. Comparing base (fc12dee) to head (b74ad33).
Report is 31 commits behind head on main.

Additional details and impacted files
@@             Coverage Diff              @@
##               main      #80      +/-   ##
============================================
+ Coverage     89.36%   89.86%   +0.49%     
- Complexity      202      223      +21     
============================================
  Files            11       11              
  Lines           395      444      +49     
============================================
+ Hits            353      399      +46     
- Misses           42       45       +3     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@lucasnetau
Copy link
Contributor Author

HI @SoftCreatR, the new regex was a bit too greedy and consumed whitespace after the comparator in filter strings, a small change to the regex

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (1)
CHANGELOG.md (1)

3-3: Consider following proper Markdown heading hierarchy

The current heading uses ### (h3) after the top-level # (h1), skipping the ## (h2) level. According to markdown best practices, heading levels should only increment by one level at a time.

-### 0.10.1
+## 0.10.1
🧰 Tools
🪛 markdownlint-cli2 (0.17.2)

3-3: Heading levels should only increment by one level at a time
Expected: h2; Actual: h3

(MD001, heading-increment)

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 74f0b33 and 390f3bb.

📒 Files selected for processing (3)
  • CHANGELOG.md (1 hunks)
  • src/Filters/QueryMatchFilter.php (1 hunks)
  • tests/JSONPathTest.php (1 hunks)
🧰 Additional context used
🪛 markdownlint-cli2 (0.17.2)
CHANGELOG.md

3-3: Heading levels should only increment by one level at a time
Expected: h2; Actual: h3

(MD001, heading-increment)

🔇 Additional comments (3)
CHANGELOG.md (1)

3-5: Changelog entry added correctly

The new version entry 0.10.1 properly documents the bug fix for whitespace handling in filter expressions with boolean operations.

🧰 Tools
🪛 markdownlint-cli2 (0.17.2)

3-3: Heading levels should only increment by one level at a time
Expected: h2; Actual: h3

(MD001, heading-increment)

src/Filters/QueryMatchFilter.php (1)

31-31: Excellent fix for the whitespace handling issue

The regex pattern has been improved to handle whitespace after the comparison value by:

  1. Adding \s* to allow optional whitespace before logical operators
  2. Making the lookahead non-capturing with (?:...) instead of (...) since we don't need to capture this group

This change successfully fixes the issue where whitespace following comparators was incorrectly processed.

tests/JSONPathTest.php (1)

327-340: Great test case addition

The new test case testQueryMatchWhitespaceIgnored properly verifies the fix by:

  1. Including intentional whitespace around operators in the filter expression
  2. Testing a real-world use case with both category and author conditions
  3. Ensuring the correct result is returned despite the extra whitespace

This test provides good coverage for the regex change made in QueryMatchFilter.php.

@lucasnetau lucasnetau force-pushed the fix-whitespace-handling branch from 390f3bb to b74ad33 Compare March 24, 2025 00:16
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (2)
CHANGELOG.md (2)

3-4: Adjust Heading Level for Consistency

The new version header is currently using a level-3 heading (### 0.10.1), but since the file starts with a top-level heading (# Changelog), it is more appropriate to use a level-2 heading for version entries. This change will also resolve the MD001 markdownlint warning regarding heading increments.

Proposed diff:

-### 0.10.1
+## 0.10.1
🧰 Tools
🪛 markdownlint-cli2 (0.17.2)

3-3: Heading levels should only increment by one level at a time
Expected: h2; Actual: h3

(MD001, heading-increment)


4-4: Clarify Changelog Message Terminology

The changelog entry reads "Fixed ignore whitespace after comparison value in filter expression". For consistency with the PR title and description—which reference the "comparator"—consider updating the wording to use "comparator" instead of "comparison value".

Proposed diff:

-- Fixed ignore whitespace after comparison value in filter expression
+- Fixed ignore whitespace after comparator in filter expression
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 390f3bb and b74ad33.

📒 Files selected for processing (3)
  • CHANGELOG.md (1 hunks)
  • src/Filters/QueryMatchFilter.php (1 hunks)
  • tests/JSONPathTest.php (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (2)
  • tests/JSONPathTest.php
  • src/Filters/QueryMatchFilter.php
🧰 Additional context used
🪛 markdownlint-cli2 (0.17.2)
CHANGELOG.md

3-3: Heading levels should only increment by one level at a time
Expected: h2; Actual: h3

(MD001, heading-increment)

@lucasnetau lucasnetau changed the title Fixed: ignore whitespace after comparator in filter expression Fixed: ignore whitespace after comparison in filter expression Mar 24, 2025
@SoftCreatR
Copy link
Owner

Thank you :)

@SoftCreatR SoftCreatR merged commit efa5596 into SoftCreatR:main Mar 24, 2025
6 checks passed
@lucasnetau lucasnetau deleted the fix-whitespace-handling branch March 24, 2025 01:19
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.

3 participants