From a274bd910ac3c4911b8c7859409efa4059fdd2a4 Mon Sep 17 00:00:00 2001 From: Shivam Mathur Date: Wed, 8 Dec 2021 04:56:29 +0530 Subject: [PATCH] Fix to handle wrong pecl versions with hyphen --- __tests__/extensions.test.ts | 1 + dist/index.js | 6 ++++-- src/extensions.ts | 4 +++- src/scripts/common.sh | 2 +- src/utils.ts | 2 +- 5 files changed, 10 insertions(+), 5 deletions(-) diff --git a/__tests__/extensions.test.ts b/__tests__/extensions.test.ts index 126131e7..45c9272e 100644 --- a/__tests__/extensions.test.ts +++ b/__tests__/extensions.test.ts @@ -59,6 +59,7 @@ describe('Extension tests', () => { ${'pecl_http'} | ${'7.3'} | ${'add_http'} ${'phalcon3'} | ${'7.3'} | ${'add_phalcon phalcon3'} ${'sqlite'} | ${'7.4'} | ${'add_extension sqlite3'} + ${'sqlsrv-1.2.3-beta1'} | ${'7.4'} | ${'add_pecl_extension sqlsrv 1.2.3beta1 extension'} ${'Xdebug'} | ${'7.4'} | ${'add_extension xdebug'} ${'xdebug-alpha'} | ${'7.4'} | ${'add_unstable_extension xdebug alpha zend_extension'} ${'xdebug2'} | ${'7.2'} | ${'add_pecl_extension xdebug 2.9.8 zend_extension'} diff --git a/dist/index.js b/dist/index.js index e6a012c1..5987db1c 100644 --- a/dist/index.js +++ b/dist/index.js @@ -332,7 +332,9 @@ async function addExtensionLinux(extension_csv, version) { let remove_script = ''; await utils.asyncForEach(extensions, async function (extension) { const version_extension = version + extension; - const [ext_name, ext_version] = extension.split('-'); + const [ext_name, ext_version] = extension + .split(/-(.+)/) + .filter(Boolean); const ext_prefix = await utils.getExtensionPrefix(ext_name); switch (true) { case /^:/.test(ext_name): @@ -1080,7 +1082,7 @@ async function extensionArray(extension_csv) { return extension .trim() .toLowerCase() - .replace(/^(:)?(php[-_]|none|zend )/, '$1'); + .replace(/^(:)?(php[-_]|none|zend )|(-[^-]*)-/, '$1$3'); }) ].filter(Boolean); } diff --git a/src/extensions.ts b/src/extensions.ts index 222f2d21..637d6db1 100644 --- a/src/extensions.ts +++ b/src/extensions.ts @@ -231,7 +231,9 @@ export async function addExtensionLinux( let remove_script = ''; await utils.asyncForEach(extensions, async function (extension: string) { const version_extension: string = version + extension; - const [ext_name, ext_version]: string[] = extension.split('-'); + const [ext_name, ext_version]: string[] = extension + .split(/-(.+)/) + .filter(Boolean); const ext_prefix = await utils.getExtensionPrefix(ext_name); switch (true) { diff --git a/src/scripts/common.sh b/src/scripts/common.sh index 9502cc4f..6cd1baf9 100644 --- a/src/scripts/common.sh +++ b/src/scripts/common.sh @@ -235,7 +235,7 @@ add_pecl_extension() { pecl_version=$(get_pecl_version "$extension" "$pecl_version") fi ext_version=$(php -r "echo phpversion('$extension');") - if [ "$ext_version" = "$pecl_version" ]; then + if [ "${ext_version/-/}" = "$pecl_version" ]; then add_log "${tick:?}" "$extension" "Enabled" else disable_extension_helper "$extension" >/dev/null 2>&1 diff --git a/src/utils.ts b/src/utils.ts index cd132ad9..ab9579f7 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -292,7 +292,7 @@ export async function extensionArray( return extension .trim() .toLowerCase() - .replace(/^(:)?(php[-_]|none|zend )/, '$1'); + .replace(/^(:)?(php[-_]|none|zend )|(-[^-]*)-/, '$1$3'); }) ].filter(Boolean); }