diff --git a/src/cxoConnection.c b/src/cxoConnection.c index a3b825e..20a5b57 100644 --- a/src/cxoConnection.c +++ b/src/cxoConnection.c @@ -643,14 +643,16 @@ static PyObject *cxoConnection_new(PyTypeObject *type, PyObject *args, // string in to the target. //----------------------------------------------------------------------------- static int cxoConnection_splitComponent(PyObject **sourceObj, - PyObject **targetObj, const char *splitString) + PyObject **targetObj, const char *splitString, int first) { PyObject *temp, *posObj; Py_ssize_t size, pos; + char *methodName; if (!*sourceObj || *targetObj) return 0; - posObj = PyObject_CallMethod(*sourceObj, "find", "s", splitString); + methodName = (first) ? "find" : "rfind"; + posObj = PyObject_CallMethod(*sourceObj, methodName, "s", splitString); if (!posObj) return -1; pos = PyInt_AsLong(posObj); @@ -742,9 +744,9 @@ static int cxoConnection_init(cxoConnection *conn, PyObject *args, conn->dsn = dsnObj; // perform some parsing, if necessary - if (cxoConnection_splitComponent(&conn->username, &passwordObj, "/") < 0) + if (cxoConnection_splitComponent(&conn->username, &passwordObj, "/", 1) < 0) return -1; - if (cxoConnection_splitComponent(&passwordObj, &conn->dsn, "@") < 0) + if (cxoConnection_splitComponent(&passwordObj, &conn->dsn, "@", 0) < 0) return -1; // setup parameters diff --git a/test/Connection.py b/test/Connection.py index 5dae663..0f08712 100644 --- a/test/Connection.py +++ b/test/Connection.py @@ -144,6 +144,22 @@ class TestCase(TestEnv.BaseTestCase): self.assertRaises(cx_Oracle.DatabaseError, connection.changepassword, TestEnv.GetMainPassword(), newPassword) + def testParsePassword(self): + "test connecting with password containing / and @ symbols" + sysRandom = random.SystemRandom() + chars = list(sysRandom.choice(string.ascii_letters) for i in range(20)) + chars[4] = "/" + chars[8] = "@" + newPassword = "".join(chars) + connection = TestEnv.GetConnection() + connection.changepassword(TestEnv.GetMainPassword(), newPassword) + try: + arg = "%s/%s@%s" % (TestEnv.GetMainUser(), newPassword, + TestEnv.GetConnectString()) + cx_Oracle.connect(arg) + finally: + connection.changepassword(newPassword, TestEnv.GetMainPassword()) + def testEncodings(self): "connection with only encoding or nencoding specified should work" connection = cx_Oracle.connect(TestEnv.GetMainUser(),