Visitar URL original
[4.x] Return an integer from the UINT filter for PHP_INT_MIN by Hackwar · Pull Request #107 · joomla-framework/filter · GitHub
Skip to content

[4.x] Return an integer from the UINT filter for PHP_INT_MIN - #107

Open
Hackwar wants to merge 1 commit into
joomla-framework:4.x-devfrom
Hackwar:4.x-uint-int-min
Open

Hackwar wants to merge 1 commit into
joomla-framework:4.x-devfrom
Hackwar:4.x-uint-int-min

Conversation

@Hackwar

@Hackwar Hackwar commented Nov 12, 2026

Copy link
Copy Markdown
Contributor

Summary of Changes

InputFilter::clean($value, 'uint') returns abs((int) $match). For PHP_INT_MIN ('-9223372036854775808', or any smaller number, which the (int) cast turns into PHP_INT_MIN) abs() cannot return an integer and returns the float 9.2233720368547758E+18, breaking the documented int return. The value is now clamped to PHP_INT_MAX.

The review also noted that all numeric filters extract the first number found anywhere in the string ('abc123' gives 123). That is long-standing, documented and covered by tests, so it is unchanged; strict validation would be a separate opt-in API.

Testing Instructions

New generic case uint_5 in InputFilterTest::casesGeneric() ((string) PHP_INT_MIN must give PHP_INT_MAX; testCleanByCallingMember() uses assertSame, so a float fails). It fails before the change and passes after it.

var_dump((new \Joomla\Filter\InputFilter())->clean('-9223372036854775808', 'uint')); // before: float(9.2233720368547758E+18), after: int(9223372036854775807)

Documentation Changes Required

docs/overview.md: the uint line in the type list mentions the clamping.

🤖 Generated with Claude Code

abs(PHP_INT_MIN) does not fit into an integer, so clean() with 'uint'
returned the float 9.2233720368547758E+18 for '-9223372036854775808'
(and for any smaller number, which the int cast saturates to
PHP_INT_MIN), breaking the documented integer return type. Clamp it to
PHP_INT_MAX.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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