Skip to content

fix: Dont use mb_detect_encoding for mb_string function calls - #924

Merged
DannyvdSluijs merged 2 commits into
mainfrom
fix/923-Avoid-encoding-detection-for-mbstring-method
Jul 24, 2026
Merged

fix: Dont use mb_detect_encoding for mb_string function calls#924
DannyvdSluijs merged 2 commits into
mainfrom
fix/923-Avoid-encoding-detection-for-mbstring-method

Conversation

@DannyvdSluijs

@DannyvdSluijs DannyvdSluijs commented Jul 16, 2026

Copy link
Copy Markdown
Collaborator

Description

Avoid mb_detect_encoding for draft 3 and 4 validations

Related Issue

Fixes #923

Type of Change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Documentation update
  • Code refactoring
  • Other (please describe):

Checklist

  • I have read the CONTRIBUTING guidelines
  • My code follows the code style of this project
  • I have added tests that prove my fix is effective or that my feature works
  • All new and existing tests pass
  • I have updated the documentation accordingly
  • My changes generate no new warnings

Additional Notes

All mb_string function calls use the default value null which results in the internal character encoding value being used which defaults to UTF-8 and allows for local overrides through setup.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

This PR updates Draft 3/4 string length validation to avoid mb_detect_encoding() during minLength/maxLength checks, addressing the nondeterminism reported in #923.

Changes:

  • Remove mb_detect_encoding() usage from StringConstraint::strlen(), relying on mb_strlen() instead.
  • Drop the now-obsolete PHPStan baseline entry related to mb_strlen() being called with a string|false encoding.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
src/JsonSchema/Constraints/StringConstraint.php Removes mb_detect_encoding() from string length calculation for Draft 3/4 validation.
phpstan-baseline.neon Removes the baseline suppression that was only needed due to the previous mb_detect_encoding() return type.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/JsonSchema/Constraints/StringConstraint.php
Co-authored-by: DannyvdSluijs <618940+DannyvdSluijs@users.noreply.github.com>
@DannyvdSluijs
DannyvdSluijs merged commit 57b7252 into main Jul 24, 2026
18 checks passed
@DannyvdSluijs
DannyvdSluijs deleted the fix/923-Avoid-encoding-detection-for-mbstring-method branch July 24, 2026 09:56
github-actions Bot added a commit that referenced this pull request Jul 24, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Avoid using mb_detect_encoding() for JSON Schema string length validation

3 participants