diff --git a/CHANGES.txt b/CHANGES.txt index ae311abf82..c5ec1056c4 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -1,5 +1,7 @@ 4.1.9 * Fix WaitQueue.Signal.awaitUninterruptibly may block forever if invoking thread is interrupted (CASSANDRA-20084) +Merged from 4.0: + * Fix autocompletion for role names/user names (CASSANDRA-20175) 4.1.8 diff --git a/pylib/cqlshlib/cql3handling.py b/pylib/cqlshlib/cql3handling.py index aaeb82c955..1beeadbc4e 100644 --- a/pylib/cqlshlib/cql3handling.py +++ b/pylib/cqlshlib/cql3handling.py @@ -1481,9 +1481,9 @@ syntax_rules += r''' ''' syntax_rules += r''' - ::= + ::= role=( | - | + | ) ; ::= "CREATE" "ROLE" ( "IF" "NOT" "EXISTS" )? @@ -1584,32 +1584,22 @@ def permission_completer(ctxt, _): @completer_for('username', 'name') def username_name_completer(ctxt, cass): - def maybe_quote(name): - if CqlRuleSet.is_valid_cql3_name(name): - return name - return "'%s'" % name - # disable completion for CREATE USER. if ctxt.matched[0][1].upper() == 'CREATE': return [Hint('')] session = cass.session - return [maybe_quote(list(row.values())[0].replace("'", "''")) for row in session.execute("LIST USERS")] + return map(maybe_escape_name, [row['name'] for row in session.execute("LIST USERS")]) @completer_for('rolename', 'role') def rolename_completer(ctxt, cass): - def maybe_quote(name): - if CqlRuleSet.is_valid_cql3_name(name): - return name - return "'%s'" % name - # disable completion for CREATE ROLE. if ctxt.matched[0][1].upper() == 'CREATE': return [Hint('')] session = cass.session - return [maybe_quote(row[0].replace("'", "''")) for row in session.execute("LIST ROLES")] + return map(maybe_escape_name, [row['role'] for row in session.execute("LIST ROLES")]) syntax_rules += r''' diff --git a/pylib/cqlshlib/test/test_cqlsh_completion.py b/pylib/cqlshlib/test/test_cqlsh_completion.py index 731b987d27..e3237d5ee7 100644 --- a/pylib/cqlshlib/test/test_cqlsh_completion.py +++ b/pylib/cqlshlib/test/test_cqlsh_completion.py @@ -950,6 +950,10 @@ class TestCqlshCompletion(CqlshCompletionCase): def test_complete_in_alter_user(self): self.trycompletions('ALTER USER ', choices=['', 'IF', '', '']) + def test_complete_in_create_role(self): + self.trycompletions('CREATE ROLE ', choices=['', 'IF']) + self.trycompletions('CREATE ROLE IF ', immediate='NOT EXISTS ') + def test_complete_in_alter_role(self): self.trycompletions('ALTER ROLE ', choices=['', 'IF', '']) self.trycompletions('ALTER ROLE IF ', immediate='EXISTS ') @@ -957,7 +961,3 @@ class TestCqlshCompletion(CqlshCompletionCase): def test_complete_in_create_user(self): self.trycompletions('CREATE USER ', choices=['', 'IF']) self.trycompletions('CREATE USER IF ', immediate='NOT EXISTS ') - - def test_complete_in_create_role(self): - self.trycompletions('CREATE ROLE ', choices=['', '', 'IF']) - self.trycompletions('CREATE ROLE IF ', immediate='NOT EXISTS ')