Skip to content

Commit c41171b

Browse files
committed
BUG27528819: Support special characters in the user and password using URI
Special characters are not allowed in the user and password for connection strings, used in the mysqlx.get_session() function. This patch fixes this issue by allowing to quote the user and password in the connection string. A URI test was added for regression.
1 parent 99b077e commit c41171b

File tree

3 files changed

+18
-3
lines changed

3 files changed

+18
-3
lines changed

docs/mysqlx/tutorials/getting_started.rst

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,15 @@ Connector/Python has a C extension for `Protobuf <https://developers.google.com/
8080
'use-pure': True
8181
})
8282
83-
The :func:`mysqlx.Schema.get_schema()` method returns a :class:`mysqlx.Schema` object. We can use this :class:`mysqlx.Schema` object to access collections and tables. X DevAPI's ability to chain all object constructions, enables you to get to the schema object in one line. For example:
83+
.. note:: The `urllib.parse.quote <https://docs.python.org/3/library/urllib.parse.html#urllib.parse.quote>`_ function should be used to quote special characters for user and password when using a connection string in the :func:`mysqlx.get_session()` function.
84+
85+
.. code-block:: python
86+
87+
from urllib.parse import quote
88+
session = mysqlx.get_session('mysqlx://root:{0}@localhost:33060?use-pure=true'
89+
''.format(quote('pass?!#%@/')))
90+
91+
The :func:`mysqlx.Session.get_schema()` method returns a :class:`mysqlx.Schema` object. We can use this :class:`mysqlx.Schema` object to access collections and tables. X DevAPI's ability to chain all object constructions, enables you to get to the schema object in one line. For example:
8492

8593
.. code-block:: python
8694

lib/mysqlx/__init__.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,8 @@ def _parse_connection_uri(uri):
115115

116116
if not host or not userinfo or ":" not in userinfo:
117117
raise InterfaceError("Malformed URI '{0}'".format(uri))
118-
settings["user"], settings["password"] = userinfo.split(":", 1)
118+
user, password = userinfo.split(":", 1)
119+
settings["user"], settings["password"] = unquote(user), unquote(password)
119120

120121
if host.startswith(("/", "..", ".")):
121122
settings["socket"] = unquote(host)

tests/test_mysqlx_connection.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,10 @@
4444
from mysqlx.protobuf import HAVE_MYSQLXPB_CEXT
4545

4646
if mysqlx.compat.PY3:
47-
from urllib.parse import quote_plus
47+
from urllib.parse import quote_plus, quote
4848
else:
4949
from urllib import quote_plus
50+
from urlparse import quote
5051

5152
from .test_mysqlx_crud import drop_table
5253

@@ -73,6 +74,11 @@
7374
"password": "", "port": 33060,
7475
"user": "user",
7576
"use-pure": True}),
77+
("user{0}:password{0}@127.0.0.1/schema?use_pure=true"
78+
"".format(quote("?!@#$%/:")), {"schema": "schema", "host": "127.0.0.1",
79+
"port": 33060, "user": "user?!@#$%/:",
80+
"password": "password?!@#$%/:",
81+
"use-pure": True}),
7682
("mysqlx://user:@127.0.0.1", {"schema": "", "host": "127.0.0.1",
7783
"password": "", "port": 33060,
7884
"user": "user"}),

0 commit comments

Comments
 (0)