From 832f4007d651edd9d74e46fb5ff45797ffe67edd Mon Sep 17 00:00:00 2001 From: Jordi Boggiano Date: Fri, 30 Apr 2021 09:40:58 +0200 Subject: [PATCH] Allow ints in source/dist reference --- src/Composer/Package/Loader/ValidatingArrayLoader.php | 4 ++-- .../Test/Package/Loader/ValidatingArrayLoaderTest.php | 7 +++++++ 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/src/Composer/Package/Loader/ValidatingArrayLoader.php b/src/Composer/Package/Loader/ValidatingArrayLoader.php index a11b9b458..4c15a798c 100644 --- a/src/Composer/Package/Loader/ValidatingArrayLoader.php +++ b/src/Composer/Package/Loader/ValidatingArrayLoader.php @@ -323,8 +323,8 @@ class ValidatingArrayLoader implements LoaderInterface if (!is_string($this->config[$srcType]['url'])) { $this->errors[] = $srcType . '.url : should be a string, '.gettype($this->config[$srcType]['url']).' given'; } - if (isset($this->config[$srcType]['reference']) && !is_string($this->config[$srcType]['reference'])) { - $this->errors[] = $srcType . '.reference : should be a string, '.gettype($this->config[$srcType]['reference']).' given'; + if (isset($this->config[$srcType]['reference']) && !is_string($this->config[$srcType]['reference']) && !is_int($this->config[$srcType]['reference'])) { + $this->errors[] = $srcType . '.reference : should be a string or int, '.gettype($this->config[$srcType]['reference']).' given'; } if (isset($this->config[$srcType]['reference']) && preg_match('{^\s*-}', $this->config[$srcType]['reference'])) { $this->errors[] = $srcType . '.reference : must not start with a "-", "'.$this->config[$srcType]['reference'].'" given'; diff --git a/tests/Composer/Test/Package/Loader/ValidatingArrayLoaderTest.php b/tests/Composer/Test/Package/Loader/ValidatingArrayLoaderTest.php index 34fff2baa..873d90376 100644 --- a/tests/Composer/Test/Package/Loader/ValidatingArrayLoaderTest.php +++ b/tests/Composer/Test/Package/Loader/ValidatingArrayLoaderTest.php @@ -194,6 +194,13 @@ class ValidatingArrayLoaderTest extends TestCase 'name' => 'npm-asset/angular--core', ), ), + array( // refs as int or string + array( + 'name' => 'foo/bar', + 'source' => array('url' => 'https://example.org', 'reference' => 1234, 'type' => 'baz'), + 'dist' => array('url' => 'https://example.org', 'reference' => 'foobar', 'type' => 'baz'), + ), + ), ); }