From db8ea452959a7d7fc1dbdf810756aae517474919 Mon Sep 17 00:00:00 2001 From: Jordi Boggiano Date: Wed, 2 Feb 2022 17:48:45 +0100 Subject: [PATCH] Fix enum parsing when the syntax is "enum foo:string {}" without space between name and type, fixes #10498 --- src/Composer/Autoload/ClassMapGenerator.php | 11 +++++++++-- .../Test/Autoload/Fixtures/php8.1/enum_backed.php | 2 +- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/src/Composer/Autoload/ClassMapGenerator.php b/src/Composer/Autoload/ClassMapGenerator.php index 3ac096772..cc2598596 100644 --- a/src/Composer/Autoload/ClassMapGenerator.php +++ b/src/Composer/Autoload/ClassMapGenerator.php @@ -272,11 +272,18 @@ class ClassMapGenerator // This is an XHP class, https://github.com/facebook/xhp $name = 'xhp'.substr(str_replace(array('-', ':'), array('_', '__'), $name), 1); } elseif ($matches['type'][$i] === 'enum') { - // In Hack, something like: + // something like: // enum Foo: int { HERP = '123'; } // The regex above captures the colon, which isn't part of // the class name. - $name = rtrim($name, ':'); + // or: + // enum Foo:int { HERP = '123'; } + // The regex above captures the colon and type, which isn't part of + // the class name. + $colonPos = strrpos($name, ':'); + if (false !== $colonPos) { + $name = substr($name, 0, $colonPos); + } } $classes[] = ltrim($namespace . $name, '\\'); } diff --git a/tests/Composer/Test/Autoload/Fixtures/php8.1/enum_backed.php b/tests/Composer/Test/Autoload/Fixtures/php8.1/enum_backed.php index d8963e056..bab09e31b 100644 --- a/tests/Composer/Test/Autoload/Fixtures/php8.1/enum_backed.php +++ b/tests/Composer/Test/Autoload/Fixtures/php8.1/enum_backed.php @@ -1,6 +1,6 @@