From 5eaed091c57cbb1b3962c85c8793fdd75c5fb182 Mon Sep 17 00:00:00 2001 From: Alex Skrypnyk Date: Sat, 13 Jan 2024 10:41:27 +1100 Subject: [PATCH] Fixed regex. --- .../installer/src/Command/InstallCommand.php | 19 ++------ .../tests/phpunit/unit/HelpersTest.php | 43 +++++++++++++++++++ .drevops/tests/bats/workflow.install.bats | 2 +- .../custom/your_site_theme/package-lock.json | 40 ++++++++--------- .../custom/your_site_theme/package.json | 34 +++++++-------- 5 files changed, 85 insertions(+), 53 deletions(-) diff --git a/.drevops/installer/src/Command/InstallCommand.php b/.drevops/installer/src/Command/InstallCommand.php index 07251c9f3..c9b39b91c 100644 --- a/.drevops/installer/src/Command/InstallCommand.php +++ b/.drevops/installer/src/Command/InstallCommand.php @@ -587,7 +587,7 @@ protected function processWebroot($dir) { static::dirReplaceContent(': web', ': ' . $new_name, $dir); static::dirReplaceContent('=web', '=' . $new_name, $dir); static::dirReplaceContent('!web', '!' . $new_name, $dir); - static::dirReplaceContent('/web', '/' . $new_name, $dir); + static::dirReplaceContent('/\/web\//', '/' . $new_name . '/', $dir); rename($dir . DIRECTORY_SEPARATOR . 'web', $dir . DIRECTORY_SEPARATOR . $new_name); } } @@ -1868,22 +1868,11 @@ protected static function dirContains($needle, $dir) { } protected static function isRegex($str) { - if (preg_match('/^(.{3,}?)[imsxuADU]*$/', $str, $m)) { - $start = substr($m[1], 0, 1); - $end = substr($m[1], -1); - - if ($start === $end) { - return !preg_match('/[*?[:alnum:] \\\\]/', $start); - } - - foreach ([['{', '}'], ['(', ')'], ['[', ']'], ['<', '>']] as $delimiters) { - if ($start === $delimiters[0] && $end === $delimiters[1]) { - return TRUE; - } - } + if ($str === '' || strlen($str) < 3) { + return FALSE; } - return FALSE; + return @preg_match($str, '') !== FALSE; } protected static function fileReplaceContent($needle, $replacement, $filename) { diff --git a/.drevops/installer/tests/phpunit/unit/HelpersTest.php b/.drevops/installer/tests/phpunit/unit/HelpersTest.php index 3e869f93d..6fdf85202 100644 --- a/.drevops/installer/tests/phpunit/unit/HelpersTest.php +++ b/.drevops/installer/tests/phpunit/unit/HelpersTest.php @@ -107,4 +107,47 @@ public static function dataProviderToCamelCase() { ]; } + /** + * @dataProvider dataProviderIsRegex + */ + public function testIsRegex($value, $expected) { + $actual = $this->callProtectedMethod(InstallCommand::class, 'isRegex', [$value]); + $this->assertEquals($expected, $actual); + } + + public static function dataProviderIsRegex() { + return [ + ['', FALSE], + + // Valid regular expressions. + ["/^[a-z]$/", TRUE], + ["#[a-z]*#i", TRUE], + ["{[0-9]+}", TRUE], + ["(\\d+)", TRUE], + ["<[A-Z]{3,6}>", TRUE], + + // Invalid regular expressions (wrong delimiters or syntax). + ["^[a-z]$", FALSE], + ["/[a-z", FALSE], + ["[a-z]+/", FALSE], + ["{[a-z]*", FALSE], + ["(a-z]", FALSE], + + // Edge cases. + // Valid, but '*' as delimiter would be invalid. + ["/a*/", TRUE], + // Empty string. + ["", FALSE], + // Just delimiters, no pattern. + ["//", FALSE], + + ['web/', FALSE], + ['web\/', FALSE], + [': web', FALSE], + ['=web', FALSE], + ['!web', FALSE], + ['/web', FALSE], + ]; + } + } diff --git a/.drevops/tests/bats/workflow.install.bats b/.drevops/tests/bats/workflow.install.bats index 866498ca7..68f1e39ff 100644 --- a/.drevops/tests/bats/workflow.install.bats +++ b/.drevops/tests/bats/workflow.install.bats @@ -56,7 +56,7 @@ load _helper.workflow.bash } @test "Workflow: DB-driven, custom webroot" { - prepare_sut "Starting DB-driven WORKFLOW tests in build directory ${BUILD_DIR}" "rootdoc" + prepare_sut "Starting DB-driven WORKFLOW with custom webroot tests in build directory ${BUILD_DIR}" "rootdoc" assert_ahoy_download_db diff --git a/web/themes/custom/your_site_theme/package-lock.json b/web/themes/custom/your_site_theme/package-lock.json index e78c961ad..131355b7b 100644 --- a/web/themes/custom/your_site_theme/package-lock.json +++ b/web/themes/custom/your_site_theme/package-lock.json @@ -9,23 +9,23 @@ "version": "1.0.0", "hasInstallScript": true, "devDependencies": { - "autoprefixer": "^9", - "eslint": "^8", - "grunt": "^1.5", - "grunt-contrib-clean": "^2", - "grunt-contrib-concat": "^2", - "grunt-contrib-copy": "^1", - "grunt-contrib-uglify": "^5", - "grunt-contrib-watch": "^1", - "grunt-exec": "^3", - "grunt-postcss": "^0.9", - "grunt-sass": "^3.1", - "grunt-sass-globbing": "^1.5", - "grunt-sass-lint": "^0.2", - "gruntify-eslint": "^5", - "patch-package": "^6", - "sass": "^1.53", - "sass-lint": "^1.13" + "autoprefixer": "^9.8.8", + "eslint": "^8.56.0", + "grunt": "^1.6.1", + "grunt-contrib-clean": "^2.0.1", + "grunt-contrib-concat": "^2.1.0", + "grunt-contrib-copy": "^1.0.0", + "grunt-contrib-uglify": "^5.2.2", + "grunt-contrib-watch": "^1.1.0", + "grunt-exec": "^3.0.0", + "grunt-postcss": "^0.9.0", + "grunt-sass": "^3.1.0", + "grunt-sass-globbing": "^1.5.1", + "grunt-sass-lint": "^0.2.4", + "gruntify-eslint": "^5.0.0", + "patch-package": "^6.5.1", + "sass": "^1.69.7", + "sass-lint": "^1.13.1" } }, "node_modules/@aashutoshrathi/word-wrap": { @@ -960,9 +960,9 @@ "dev": true }, "node_modules/electron-to-chromium": { - "version": "1.4.629", - "resolved": "https://registry.npmjs.org/electron-to-chromium/-/electron-to-chromium-1.4.629.tgz", - "integrity": "sha512-5UUkr3k3CZ/k+9Sw7vaaIMyOzMC0XbPyprKI3n0tbKDqkzTDOjK4izm7DxlkueRMim6ZZQ1ja9F7hoFVplHihA==", + "version": "1.4.630", + "resolved": "https://registry.npmjs.org/electron-to-chromium/-/electron-to-chromium-1.4.630.tgz", + "integrity": "sha512-osHqhtjojpCsACVnuD11xO5g9xaCyw7Qqn/C2KParkMv42i8jrJJgx3g7mkHfpxwhy9MnOJr8+pKOdZ7qzgizg==", "dev": true }, "node_modules/emoji-regex": { diff --git a/web/themes/custom/your_site_theme/package.json b/web/themes/custom/your_site_theme/package.json index 4df362327..a02440c78 100644 --- a/web/themes/custom/your_site_theme/package.json +++ b/web/themes/custom/your_site_theme/package.json @@ -4,23 +4,23 @@ "private": true, "description": "NPM dependencies for YOURSITE project", "devDependencies": { - "autoprefixer": "^9", - "eslint": "^8", - "grunt": "^1.5", - "grunt-contrib-clean": "^2", - "grunt-contrib-concat": "^2", - "grunt-contrib-copy": "^1", - "grunt-contrib-uglify": "^5", - "grunt-contrib-watch": "^1", - "grunt-exec": "^3", - "grunt-postcss": "^0.9", - "grunt-sass": "^3.1", - "grunt-sass-globbing": "^1.5", - "grunt-sass-lint": "^0.2", - "gruntify-eslint": "^5", - "patch-package": "^6", - "sass": "^1.53", - "sass-lint": "^1.13" + "autoprefixer": "^9.8.8", + "eslint": "^8.56.0", + "grunt": "^1.6.1", + "grunt-contrib-clean": "^2.0.1", + "grunt-contrib-concat": "^2.1.0", + "grunt-contrib-copy": "^1.0.0", + "grunt-contrib-uglify": "^5.2.2", + "grunt-contrib-watch": "^1.1.0", + "grunt-exec": "^3.0.0", + "grunt-postcss": "^0.9.0", + "grunt-sass": "^3.1.0", + "grunt-sass-globbing": "^1.5.1", + "grunt-sass-lint": "^0.2.4", + "gruntify-eslint": "^5.0.0", + "patch-package": "^6.5.1", + "sass": "^1.69.7", + "sass-lint": "^1.13.1" }, "browserslist": [ "last 2 versions",