Skip to content

Commit 8d806d7

Browse files
committed
fix: add / separator before Windows paths in inet:// protocol URLs; fix test assertion
1 parent d4f545a commit 8d806d7

File tree

2 files changed

+8
-7
lines changed

2 files changed

+8
-7
lines changed

src/firebird/driver/core.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2180,7 +2180,7 @@ def _connect_helper(dsn: str, host: str, port: str, database: str, protocol: Net
21802180
# Unix absolute path - use double slash so Firebird keeps the leading /
21812181
dsn += f'/{database}' # Results in inet://host//absolute/path
21822182
elif ':' in database: # Windows path (e.g., C:\...)
2183-
dsn += database # Concatenate directly without separator
2183+
dsn += f'/{database}' # Results in inet://host:port/D:\path
21842184
else: # Relative/alias
21852185
dsn += f'/{database}'
21862186
else:

tests/test_connection.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -162,21 +162,22 @@ def test_connect_config(fb_vars, db_file, driver_cfg):
162162

163163
if host:
164164
# protocols
165-
# For protocol URLs with absolute paths, we need double slash to preserve leading /
166-
# inet://host//absolute/path so Firebird doesn't strip the leading /
165+
# For protocol URLs the path always needs a / separator:
166+
# - Unix: inet://host//absolute/path (double slash to keep the leading /)
167+
# - Windows: inet://host:port/D:\path (single slash before drive letter)
167168
if str(db_file).startswith('/'):
168-
dsn = f'{host}:{port}/{db_file}' # Extra / for absolute paths
169+
proto_path = f'{host}:{port}/{db_file}' # Extra / for Unix absolute paths
169170
else:
170-
dsn = f'{host}:{port}{db_file}'
171+
proto_path = f'{host}:{port}/{db_file}' # Single / for Windows drive-letter paths
171172
cfg = driver_cfg.get_database('test_db1')
172173
cfg.protocol.value = NetProtocol.INET
173174
with connect('test_db1') as con:
174175
assert con._att is not None
175-
assert con.dsn == f'inet://{dsn}'
176+
assert con.dsn == f'inet://{proto_path}'
176177
cfg.protocol.value = NetProtocol.INET4
177178
with connect('test_db1') as con:
178179
assert con._att is not None
179-
assert con.dsn == f'inet4://{dsn}'
180+
assert con.dsn == f'inet4://{proto_path}'
180181

181182
def test_properties(db_connection):
182183
con = db_connection # Use the fixture

0 commit comments

Comments
 (0)