Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ Bug Fixes
--------
* Read `/source` files and the `\e` editor file as UTF-8 instead of the locale encoding, so non-ASCII SQL no longer fails or is mis-decoded under non-UTF-8 locales.
* Open the audit log and the `\T`/`\o` output files as UTF-8, so non-ASCII output no longer fails under non-UTF-8 locales.
* Bracket IPv6 hosts in the DSN shown and saved by `\dsn`, so a saved alias for `::1` can be used to connect again.
* Support `DELIMITER` in batch input (`mycli < file.sql`, `--batch`), so dumps with triggers or routines restore.
* Read `--batch` files and read and write `--checkpoint` files as UTF-8, fixing `--resume` and non-ASCII batch files on Windows.

Expand Down
1 change: 1 addition & 0 deletions mycli/AUTHORS.txt
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ Contributors:
* Wei-Lun Li
* Shaurya Kesarwani
* Alex Castillo
* Karim Masmoudi
* Jay Hemnani
* Alpenj

Expand Down
3 changes: 3 additions & 0 deletions mycli/packages/special_commands/special_command_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,9 @@ def format_connection_dsn(
if user_part := urlquote(user or ''):
user_part = f'{user_part}@'
host_part = host or 'localhost'
if ':' in host_part and not host_part.startswith('['):
# IPv6 literals must be bracketed so the port can be told apart
host_part = f'[{host_part}]'
port_part = f':{port}' if port is not None else ''
if db_part := urlquote(database or ''):
db_part = f'/{db_part}'
Expand Down
16 changes: 16 additions & 0 deletions mycli_test/pytests/test_special_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import tempfile
from types import SimpleNamespace
from unittest.mock import MagicMock
from urllib.parse import urlparse

import pymysql
import pytest
Expand Down Expand Up @@ -327,6 +328,21 @@ def test_format_connection_dsn_includes_ssh_jump() -> None:
)


def test_format_connection_dsn_brackets_ipv6_host() -> None:
dsn = format_connection_dsn(
user='alice',
host='::1',
port=3307,
database='prod',
socket=None,
character_set=None,
)
assert dsn == 'mysql://alice@[::1]:3307/prod'
uri = urlparse(dsn)
assert uri.hostname == '::1'
assert uri.port == 3307


def test_format_connection_dsn_includes_encoded_kubectl_resource() -> None:
assert (
format_connection_dsn(
Expand Down
Loading