php / php/php-src

Add FILTER_VALIDATE_STRLEN for UTF-8 string length validation

Open
#21,428 6 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Extension: filter Feature Status: Requires RFC
Dominant language
C
Stars
40.4k
Forks
8.1k
Avg merge
2d 13h
Merged PRs (30d)
96

Description

Description

I would like to propose a new filter validator FILTER_VALIDATE_STRLEN that validates the length of a UTF-8 string.

The length is counted in Unicode code points. Grapheme clusters are not considered.

The validator supports min_len and max_len options and does not depend on the mbstring extension.

A prototype implementation is provided in the accompanying pull request.

$options = [
    'options' => [
        'max_len' => 2,
        'default' => 'error',
    ],
];

var_dump(
    filter_var('🐘🐘🐘', FILTER_VALIDATE_STRLEN, $options)
);

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reviewing the accompanying prototype implementation and the existing filter validator entry points. Check the min_len, max_len, default, UTF-8 code-point counting, and no-mbstring requirements, then verify that the validator handles the example and its boundary cases consistently.

Written by the indexing model from the issue text.

Assessment

Tech stack
c, php
Domain
backend
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.