Skip to content

Inconsistent and incomplete ECMA-to-PCRE pattern replacements in createPregMatchPattern #917

@DannyvdSluijs

Description

@DannyvdSluijs

Description

createPregMatchPattern appears in six constraint files across Draft 6, 7, and 2019-09, but the active replacements are inconsistent between files and several ECMA regex shorthand replacements are commented out without explanation.

Affected Files

  • src/JsonSchema/Constraints/Drafts/Draft06/AdditionalPropertiesConstraint.php
  • src/JsonSchema/Constraints/Drafts/Draft06/PatternPropertiesConstraint.php
  • src/JsonSchema/Constraints/Drafts/Draft07/AdditionalPropertiesConstraint.php
  • src/JsonSchema/Constraints/Drafts/Draft07/PatternPropertiesConstraint.php
  • src/JsonSchema/Constraints/Drafts/Draft2019/AdditionalPropertiesConstraint.php
  • src/JsonSchema/Constraints/Drafts/Draft2019/PatternPropertiesConstraint.php

Current State

The replacements active in each class differ, and several are left commented out:

Replacement PatternConstraint (all drafts) PatternPropertiesConstraint (all drafts) AdditionalPropertiesConstraint (all drafts)
\D[^0-9] active commented out commented out
\d[0-9] active active commented out
\p{digit} → ... [0-9] [0-9] \p{Nd} (inconsistent)
\w[A-Za-z0-9_] active commented out commented out
\W[^A-Za-z0-9_] active commented out commented out
\s[\s\x{200B}] active commented out commented out
\p{Letter}\p{L} active active active

PatternConstraint (which validates string values against a pattern keyword) has all replacements active. The PatternPropertiesConstraint and AdditionalPropertiesConstraint versions (which match property key names against patterns) are missing most of them, with no explanation for why they should differ.

There is also a concrete inconsistency: \p{digit} maps to \p{Nd} in AdditionalPropertiesConstraint but to [0-9] in PatternPropertiesConstraint and PatternConstraint.

Expected Behaviour

  • A decision should be made on whether the commented-out replacements should be enabled or permanently removed.
  • If there is a deliberate reason for PatternPropertiesConstraint / AdditionalPropertiesConstraint to use a different (reduced) set of replacements compared to PatternConstraint, that reason should be documented.
  • The \p{digit} mapping should be consistent across all files.
  • Commented-out code should not remain in the codebase without explanation.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions