Skip to content

Conversation

@yoeunes
Copy link
Owner

@yoeunes yoeunes commented Dec 6, 2025

Description

Improves the regex parser with enhanced caching, a new safety check for ReDoS vulnerabilities, and various code style and optimization improvements.

Type of Change

  • Bug fix
  • New feature
  • Breaking change
  • Documentation update

Related Issue

Fixes #(issue number)

Testing

  • Unit tests added/updated
  • Tests pass locally
  • No new warnings

Checklist

  • My code follows the project style
  • I have run phpstan and phpunit
  • Documentation updated if needed
  • No breaking changes without discussion

Bumps versions for PHPUnit, PHPStan, and PHP-CS-Fixer.
Ensures the project uses the latest minor and patch releases for these development tools.
Improves cache adapter efficiency by decoding compiled cache payloads (small PHP scripts) into RegexNode instances before storing them in the cache.

This reduces latency for subsequent reads, as the AST object is readily available, and prevents the need to evaluate the payload string repeatedly. This applies to both PSR-6 and PSR-16 cache adapters.

Also introduces a ValidationResult DTO to provide more comprehensive regex validation outcomes, including validity status, error messages, and complexity scores.
Introduces a method to determine if a regular expression is safe from potential ReDoS vulnerabilities.

The new method analyzes the regex and flags it as unsafe if the ReDoS analyzer detects HIGH or CRITICAL severity issues.
Extends the non-capturing group unwrapping optimization to include more node types.

This change removes unnecessary non-capturing groups when they contain a single atomic node like character classes, anchors, assertions, unicode nodes, or unicode property nodes, resulting in more efficient regular expressions.
Marks several classes as final to prevent inheritance and ensure code stability.

Enables the `final_class` fixer in PHP CS Fixer to automatically add the `final` keyword where appropriate.

Improves code consistency and maintainability by enforcing final classes and applying code style rules.
Updates classes to utilize the `readonly` keyword where appropriate for improved code immutability and static analysis.
Also, it explicitly defines the types for class constants.

This change promotes more robust and maintainable code.
Removes the `final` keyword from the `ParserException` class.

This change allows for extending the `ParserException` class, providing more flexibility in handling specific parsing error scenarios.
Disables the final class fixer in the php-cs-fixer configuration.
This allows for greater flexibility in class inheritance during development.
Refactors tests to remove redundant assertions, focusing on behavior rather than implementation details.

Improves test robustness by handling potential exceptions during regex sample generation.

Addresses potential issues with invalid PCRE patterns in ReverseCompilerTest by adding error handling and context for conditional/subroutine patterns.
Refactors the reverse compilation tests to improve reliability and provide more informative error messages.

Specifically, it ensures that sample generation failures are handled gracefully by skipping the sample match test but still validating the recompiled regex. It also replaces direct constant access for preg errors with namespaced access.
@yoeunes yoeunes merged commit bd749fb into main Dec 6, 2025
7 of 8 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.

2 participants