Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions NEWS
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ PHP NEWS
. Fix incorrect argument positions for uninitialized calendar arguments in
IntlCalendar::equals(), ::before(), ::after(), and ::isEquivalentTo().
(Weilin Du)
. Fixed Spoofchecker restriction-level APIs to only be exposed with ICU 53
and later. (Graham Campbell)

- Phar:
. Fixed a bypass of the magic ".phar" directory protection in
Expand Down
4 changes: 4 additions & 0 deletions ext/intl/spoofchecker/spoofchecker.stub.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ class Spoofchecker
public const int INVISIBLE = UNKNOWN;
/** @cvalue USPOOF_CHAR_LIMIT */
public const int CHAR_LIMIT = UNKNOWN;
#if U_ICU_VERSION_MAJOR_NUM >= 53

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.

Ideally, we may still want to support ICU 51 since it is technically >50.1, which is our minimum supported version in 8.4. So I'd suggest to only guard USPOOF_SINGLE_SCRIPT_RESTRICTIVE under ICU 53 and guard the rest under ICU 51. This benefit people who are using 51 < ICU version < 53 that they should have access to these const that exists since ICU 51

That is, I suggest to change this guard to >= 51 and specifically list USPOOF_SINGLE_SCRIPT_RESTRICTIVE out and put it in a ICU >= 53 guard.

/** @cvalue USPOOF_ASCII */
public const int ASCII = UNKNOWN;
/** @cvalue USPOOF_HIGHLY_RESTRICTIVE */
Expand All @@ -33,6 +34,7 @@ class Spoofchecker
public const int SINGLE_SCRIPT_RESTRICTIVE = UNKNOWN;
/** @cvalue USPOOF_MIXED_NUMBERS */
public const int MIXED_NUMBERS = UNKNOWN;
#endif
#if U_ICU_VERSION_MAJOR_NUM >= 62
/** @cvalue USPOOF_HIDDEN_OVERLAY */
public const int HIDDEN_OVERLAY = UNKNOWN;
Expand Down Expand Up @@ -69,7 +71,9 @@ public function setAllowedLocales(string $locales): void {}
/** @tentative-return-type */
public function setChecks(int $checks): void {}

#if U_ICU_VERSION_MAJOR_NUM >= 53
/** @tentative-return-type */
public function setRestrictionLevel(int $level): void {}
#endif
public function setAllowedChars(string $pattern, int $patternOptions = 0): void {}
}
22 changes: 21 additions & 1 deletion ext/intl/spoofchecker/spoofchecker_arginfo.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions ext/intl/spoofchecker/spoofchecker_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@ PHP_METHOD(Spoofchecker, setChecks)
}
/* }}} */

#if U_ICU_VERSION_MAJOR_NUM >= 53
/* TODO Document this method on PHP.net */
/* {{{ Set the loosest restriction level allowed for strings. */
PHP_METHOD(Spoofchecker, setRestrictionLevel)
Expand Down Expand Up @@ -163,6 +164,7 @@ PHP_METHOD(Spoofchecker, setRestrictionLevel)
uspoof_setRestrictionLevel(co->uspoof, (URestrictionLevel)level);
}
/* }}} */
#endif

PHP_METHOD(Spoofchecker, setAllowedChars)
{
Expand Down
6 changes: 6 additions & 0 deletions ext/intl/tests/spoofchecker_007.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@ spoofchecker with restriction level
intl
--SKIPIF--
<?php if(!class_exists("Spoofchecker")) print 'skip'; ?>
<?php
$r = new ReflectionClass("SpoofChecker");
if (false === $r->getConstant("SINGLE_SCRIPT_RESTRICTIVE")) {
die("skip Incompatible ICU version");

@LamentXU123 LamentXU123 Jun 8, 2026

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.

Suggested change
die("skip Incompatible ICU version");
die("skip for ICU version < 53");

to align with other skip message in the intl extension. Might need to consider to change the version message to 51 if the upper suggestion is agreed.

}
?>
--FILE--
<?php

Expand Down
6 changes: 6 additions & 0 deletions ext/intl/tests/spoofchecker_supported_icu57_apis.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@ Spoofchecker exposes restriction-level APIs on all supported ICU versions
intl
--SKIPIF--
<?php if (!class_exists("Spoofchecker")) print 'skip'; ?>
<?php
$r = new ReflectionClass("Spoofchecker");
if (false === $r->getConstant("SINGLE_SCRIPT_RESTRICTIVE")) {
die("skip Incompatible ICU version");

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.

Suggested change
die("skip Incompatible ICU version");
die("skip for ICU version < 53");

Ditto.

}
?>
--FILE--
<?php
$r = new ReflectionClass("Spoofchecker");
Expand Down
2 changes: 2 additions & 0 deletions ext/intl/tests/spoofchecker_unknown_restriction_level.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ intl
--SKIPIF--
<?php
if (!class_exists("Spoofchecker")) print 'skip';

if (!method_exists(new Spoofchecker(), 'setRestrictionLevel')) print 'skip ICU version < 53';

@LamentXU123 LamentXU123 Jun 8, 2026

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.

Suggested change
if (!method_exists(new Spoofchecker(), 'setRestrictionLevel')) print 'skip ICU version < 53';
if (!method_exists(new Spoofchecker(), 'setRestrictionLevel')) print 'skip for ICU version < 53';

Ditto. However this can always be accepted whether we agree to move the majority of your guard to 51 because the setRestrictionLevel is guarded under 53 anyways.

?>
--FILE--
<?php
Expand Down
Loading