Skip to content

Commit

Permalink
Fixed regex.
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexSkrypnyk committed Jan 12, 2024
1 parent 95d78c6 commit 5eaed09
Show file tree
Hide file tree
Showing 5 changed files with 85 additions and 53 deletions.
19 changes: 4 additions & 15 deletions .drevops/installer/src/Command/InstallCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
Expand Down Expand Up @@ -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) {
Expand Down
43 changes: 43 additions & 0 deletions .drevops/installer/tests/phpunit/unit/HelpersTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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],
];
}

}
2 changes: 1 addition & 1 deletion .drevops/tests/bats/workflow.install.bats
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
40 changes: 20 additions & 20 deletions web/themes/custom/your_site_theme/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

34 changes: 17 additions & 17 deletions web/themes/custom/your_site_theme/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down

0 comments on commit 5eaed09

Please sign in to comment.