Ticket #2448 (closed defect: fixed)
Opened 6 years ago
Last modified 2 years ago
[patch] Trac does not allow spaces in postgres database passwords
| Reported by: | jacob@… | Owned by: | jhampton |
|---|---|---|---|
| Priority: | normal | Milestone: | 0.12 |
| Component: | general | Version: | devel |
| Severity: | normal | Keywords: | |
| Cc: | pacopablo@… | ||
| Release Notes: | |||
| API Changes: | |||
Description
Trac currently doesn't allow spaces in postgres database passwords; the following patch (against r2616) fixes it:
Index: trac/db/postgres_backend.py
===================================================================
--- trac/db/postgres_backend.py (revision 2616)
+++ trac/db/postgres_backend.py (working copy)
@@ -91,7 +91,7 @@
if user:
dsn.append('user=' + user)
if password:
- dsn.append('password=' + password)
+ dsn.append("password='%s'" % password)
if host:
dsn.append('host=' + host)
if port:
Attachments
Change History
comment:1 Changed 5 years ago by sid
- Keywords review added
comment:2 Changed 5 years ago by pacopablo
- Cc pacopablo@… added
comment:3 Changed 5 years ago by mgood
- Owner changed from jonas to mgood
Jacob or John can you test this patch which quotes all parameters to the DSN:
-
trac/db/postgres_backend.py
119 119 if 'host' in params: 120 120 host = params['host'] 121 121 if psycopg: 122 dsn = [] 123 if path: 124 dsn.append('dbname=' + path) 125 if user: 126 dsn.append('user=' + user) 127 if password: 128 dsn.append('password=' + password) 129 if host: 130 dsn.append('host=' + host) 131 if port: 132 dsn.append('port=' + str(port)) 133 cnx = psycopg.connect(' '.join(dsn)) 122 dsn = {'dbname': path, 'user': user, 'password': password, 123 'host': host, 'port': port} 124 cnx = psycopg.connect(' '.join([("%s='%s'" % k,v) for k,v 125 in dsn.iteritems() if v])) 134 126 cnx.set_client_encoding('UNICODE') 135 127 else: 136 128 # Don't use chatty, inefficient server-side cursors.
comment:4 Changed 5 years ago by mgood
- Milestone set to 0.11
comment:5 Changed 2 years ago by rblank
- Keywords bitesized added
comment:6 Changed 2 years ago by jhampton
- Keywords review bitesized removed
- Milestone changed from next-minor-0.12.x to 0.12
- Owner changed from mgood to jhampton
- Status changed from new to assigned
OK, so patch is mostly correct. The bigger issue is that enabling spaces also screws up the db uri parser. I'll start working on a patch for that.
comment:7 Changed 2 years ago by jhampton
Fixed in [9225]
comment:8 Changed 2 years ago by jhampton
- Resolution set to fixed
- Status changed from assigned to closed
comment:9 Changed 2 years ago by cboos
- Resolution fixed deleted
- Status changed from closed to reopened
Meep.
Python 2.4.4 (#71, Oct 18 2006, 08:34:43) [MSC v.1310 32 bit (Intel)] on win32 >>> from itertools import combinations Traceback (most recent call last): File "<stdin>", line 1, in ? ImportError: cannot import name combinations ActivePython 2.5.4.4 (ActiveState Software Inc.) based on Python 2.5.4 (r254:67916, Apr 27 2009, 15:41:14) [MSC v.1310 32 bit (Intel)] on win32 >>> from itertools import combinations Traceback (most recent call last): File "<stdin>", line 1, in <module> ImportError: cannot import name combinations
Plus note that itertools is riddled with memory issues, try to avoid it (ok, for the tests it's fine).
comment:10 Changed 2 years ago by jhampton
- Resolution set to fixed
- Status changed from reopened to closed
See what I get for writing tests? :)
Test fixed in [9229]



patch attached, needs to be reviewed