Skip to content

fix: honor default values for float, URL, IP and MAC filters - #11

Open
malekkadri wants to merge 1 commit into
francescotinti:mainfrom
malekkadri:fix/filter-validator-default-values
Open

malekkadri wants to merge 1 commit into
francescotinti:mainfrom
malekkadri:fix/filter-validator-default-values

Conversation

@malekkadri

Copy link
Copy Markdown

Some filter_var() validators ignore the default option when validation fails.

For example:

var_dump(filter_var('invalid', FILTER_VALIDATE_IP, [
    'options' => ['default' => '127.0.0.1'],
]));

PHP returns "127.0.0.1", while phpr returns false.

The same behaviour affects FILTER_VALIDATE_FLOAT, FILTER_VALIDATE_URL and FILTER_VALIDATE_MAC.

This PR reuses the existing default_or_miss() helper, which is already used by the other validators.

Added regression coverage for default values, FILTER_NULL_ON_FAILURE and successful validation.

The regression tests pass locally.

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.

1 participant