This is an automated email from the ASF dual-hosted git repository.
djoshi pushed a commit to branch trunk
in repository https://gitbox.apache.org/repos/asf/cassandra.git
The following commit(s) were added to refs/heads/trunk by this push:
new 781e486 Fix CQLSH to avoid arguments being evaluated
781e486 is described below
commit 781e4862faab8dd10382ec296b122592edd0f6f0
Author: Zhao Yang <[email protected]>
AuthorDate: Tue Mar 31 17:52:43 2020 +0800
Fix CQLSH to avoid arguments being evaluated
Patch By Zhao Yang; reviewed by Dinesh Joshi and Brandon Williams for
CASSANDRA-15660
---
CHANGES.txt | 1 +
bin/cqlsh | 62 +++++++++++++++++++++++++++++++------------------------------
2 files changed, 33 insertions(+), 30 deletions(-)
diff --git a/CHANGES.txt b/CHANGES.txt
index ecd3562..8f19c2a 100644
--- a/CHANGES.txt
+++ b/CHANGES.txt
@@ -1,4 +1,5 @@
4.0-alpha4
+ * Fix CQLSH to avoid arguments being evaluated (CASSANDRA-15660)
* Correct Visibility and Improve Safety of Methods in LatencyMetrics
(CASSANDRA-15597)
* Allow cqlsh to run with Python2.7/Python3.6+
(CASSANDRA-15659,CASSANDRA-15573)
* Improve logging around incremental repair (CASSANDRA-15599)
diff --git a/bin/cqlsh b/bin/cqlsh
index bce00f8..0774d52 100755
--- a/bin/cqlsh
+++ b/bin/cqlsh
@@ -17,36 +17,39 @@
# shell script to find a suitable Python interpreter and run cqlsh.py
-# parse arguments
-PARAMS=""
-
# Use the Python that is specified in the env
if [ -n "$CQLSH_PYTHON" ]; then
USER_SPECIFIED_PYTHON="$CQLSH_PYTHON"
fi
-while [ $# -gt 0 ]; do
- case "$1" in
- --python)
- if [ $# -lt 2 ]; then
- echo "You must specify a python interpreter path with the
--python option"
- exit 1
- fi
- USER_SPECIFIED_PYTHON="$2"
- shift
- shift
- ;;
- --)
- shift
- break
- ;;
- *)
- PARAMS="$PARAMS $1"
- shift
- ;;
- esac
+
+# filter "--python" option and its value, and keep remaining arguments as it is
+USER_SPECIFIED_PYTHON_OPTION=false
+for arg do
+ shift
+ case "$arg" in
+ --python)
+ USER_SPECIFIED_PYTHON_OPTION=true
+ ;;
+ --)
+ break
+ ;;
+ *)
+ if [ "$USER_SPECIFIED_PYTHON_OPTION" = true ] ; then
+ USER_SPECIFIED_PYTHON_OPTION=false
+ USER_SPECIFIED_PYTHON="$arg"
+ else
+ set -- "$@" "$arg"
+ fi
+ ;;
+ esac
done
+if [ "$USER_SPECIFIED_PYTHON_OPTION" = true ] ; then
+ echo "You must specify a python interpreter path with the --python option"
+ exit 1
+fi
+
# get a version string for a Python interpreter
get_python_version() {
interpreter=$1
@@ -68,14 +71,13 @@ is_supported_version() {
}
run_if_supported_version() {
- interpreter="$1"
- params="$2"
+ # get the interpreter and remove it from argument
+ interpreter="$1" shift
+
version=$(get_python_version "$interpreter")
if [ -n "$version" ]; then
if [ "$(is_supported_version "$version")" = "supported" ]; then
- # We need the params to be unquoted, otherwise the shell will just
interpret it as one giant string
- # shellcheck disable=SC2086
- exec "$interpreter" "$($interpreter -c "import os;
print(os.path.dirname(os.path.realpath('$0')))")/cqlsh.py" $params
+ exec "$interpreter" "$($interpreter -c "import os;
print(os.path.dirname(os.path.realpath('$0')))")/cqlsh.py" "$@"
exit
fi
fi
@@ -84,11 +86,11 @@ run_if_supported_version() {
if [ "$USER_SPECIFIED_PYTHON" != "" ]; then
# run a user specified Python interpreter
- run_if_supported_version "$USER_SPECIFIED_PYTHON" "$PARAMS"
+ run_if_supported_version "$USER_SPECIFIED_PYTHON" "$@"
else
# try unqualified python first, then python3, then python2.7
for interpreter in python python3 python2.7; do
- run_if_supported_version "$interpreter" "$PARAMS"
+ run_if_supported_version "$interpreter" "$@"
done
fi
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]