Merge pull request #22634 from outis/fix-sed-pw

Fix sed pw
This commit is contained in:
Claudio Sanches 2019-02-06 14:43:32 -02:00 committed by GitHub
commit 82c1f8f81b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 11 additions and 2 deletions

View File

@ -14,10 +14,17 @@
$ tests/bin/install.sh <db-name> <db-user> <db-password> [db-host] $ tests/bin/install.sh <db-name> <db-user> <db-password> [db-host]
``` ```
Sample usage: The `<db-password>` will be set as given. Previously, you would have needed to escape certain characters (forward & backward slashes, and ampersand), but install.sh now escapes them when it needs to internally. You may still need to quote strings with backslashes to prevent them from being processed by the shell or other programs.
Sample usages:
$ tests/bin/install.sh woocommerce_tests root root $ tests/bin/install.sh woocommerce_tests root root
# The actual password only has a single backslash, but it's escaped
# to prevent the shell and PHP from treating it as a backspace character
$ tests/bin/install.sh woocommerce_tests root 'a\\b/&'
# Previously, the password would have had to be passed as 'a\\\\b\/\&'
**Important**: The `<db-name>` database will be created if it doesn't exist and all data will be removed during testing. **Important**: The `<db-name>` database will be created if it doesn't exist and all data will be removed during testing.
## Running Tests ## Running Tests

View File

@ -91,7 +91,9 @@ install_test_suite() {
sed $ioption "s:dirname( __FILE__ ) . '/src/':'$WP_CORE_DIR/':" "$WP_TESTS_DIR"/wp-tests-config.php sed $ioption "s:dirname( __FILE__ ) . '/src/':'$WP_CORE_DIR/':" "$WP_TESTS_DIR"/wp-tests-config.php
sed $ioption "s/youremptytestdbnamehere/$DB_NAME/" "$WP_TESTS_DIR"/wp-tests-config.php sed $ioption "s/youremptytestdbnamehere/$DB_NAME/" "$WP_TESTS_DIR"/wp-tests-config.php
sed $ioption "s/yourusernamehere/$DB_USER/" "$WP_TESTS_DIR"/wp-tests-config.php sed $ioption "s/yourusernamehere/$DB_USER/" "$WP_TESTS_DIR"/wp-tests-config.php
sed $ioption "s/yourpasswordhere/$DB_PASS/" "$WP_TESTS_DIR"/wp-tests-config.php # escape the regex delim if not already escaped (i.e. if preceded by an even number of backslashes)
E_DB_PASS=$(echo $DB_PASS | sed -E -e 's%([/&\\])%\\\1%g')
sed $ioption "s/yourpasswordhere/${E_DB_PASS}/" "$WP_TESTS_DIR"/wp-tests-config.php
sed $ioption "s|localhost|${DB_HOST}|" "$WP_TESTS_DIR"/wp-tests-config.php sed $ioption "s|localhost|${DB_HOST}|" "$WP_TESTS_DIR"/wp-tests-config.php
fi fi