aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authornsfisis <nsfisis@gmail.com>2026-07-20 06:28:35 +0900
committernsfisis <nsfisis@gmail.com>2026-07-20 06:28:35 +0900
commitf74e69ad1147618efd174791ac12904c0dcc6e28 (patch)
treea0dc3f49338c470b7197d5e1f6a38975b4b1da79
parentde56316efae59dc1bfd517b90bc66611d017a52a (diff)
downloadphp-shirabe-f74e69ad1147618efd174791ac12904c0dcc6e28.tar.gz
php-shirabe-f74e69ad1147618efd174791ac12904c0dcc6e28.tar.zst
php-shirabe-f74e69ad1147618efd174791ac12904c0dcc6e28.zip
fix(semver): stop classical pattern matching 6+ digit versions
The regex crate parses PCRE's possessive \d{1,5}+ as a stacked repetition (?:\d{1,5})+, i.e. \d+, so date versions like 20121020 matched the classical pattern and normalized to 20121020.0.0.0 instead of falling through to the date(time) pattern like PHP. The plain \d{1,5} is equivalent to the possessive form here per the regex-porting rules. Un-ignore test_find_recommended_require_version which this had blocked. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
-rw-r--r--crates/shirabe-semver/src/version_parser.rs7
-rw-r--r--crates/shirabe/tests/package/version/version_selector_test.rs4
2 files changed, 6 insertions, 5 deletions
diff --git a/crates/shirabe-semver/src/version_parser.rs b/crates/shirabe-semver/src/version_parser.rs
index c27f7819..287716d9 100644
--- a/crates/shirabe-semver/src/version_parser.rs
+++ b/crates/shirabe-semver/src/version_parser.rs
@@ -128,8 +128,13 @@ impl VersionParser {
let mut matches: Vec<Option<String>> = Vec::new();
// match classical versioning
+ // Regex pattern compatibility:
+ // PCRE's possessive `\d{1,5}+` is parsed by the `regex` crate as a stacked
+ // repetition `(?:\d{1,5})+` (i.e. `\d+`), which wrongly let 6+ digit numbers
+ // (e.g. date versions like 20121020) match here. The plain `\d{1,5}` is
+ // equivalent to the possessive form for this pattern.
let classical_pattern = format!(
- "{{^v?(\\d{{1,5}}+)(\\.\\d++)?(\\.\\d++)?(\\.\\d++)?{}$}}i",
+ "{{^v?(\\d{{1,5}})(\\.\\d++)?(\\.\\d++)?(\\.\\d++)?{}$}}i",
MODIFIER_REGEX
);
if shirabe_php_shim::preg_match(&classical_pattern, &version, &mut matches) {
diff --git a/crates/shirabe/tests/package/version/version_selector_test.rs b/crates/shirabe/tests/package/version/version_selector_test.rs
index 7722b228..7c6eca78 100644
--- a/crates/shirabe/tests/package/version/version_selector_test.rs
+++ b/crates/shirabe/tests/package/version/version_selector_test.rs
@@ -543,10 +543,6 @@ fn test_false_returned_on_no_packages() {
}
#[test]
-#[ignore = "date-based cases (v20121020) fail: shirabe_semver::VersionParser::normalize yields \
- 20121020.0.0.0 instead of PHP's date-aware 20121020, so find_recommended_require_version \
- returns ^20121020.0 rather than leaving the version untouched. Faithful port; un-ignore \
- once normalize handles date(time) versions like PHP"]
fn test_find_recommended_require_version() {
let php_version = format!(
"{}.{}.{}",