From 916e702f37c74d1ede0af4e6a0c299c730efbb71 Mon Sep 17 00:00:00 2001 From: Olivier Mehani Date: Tue, 17 Mar 2026 11:24:06 +1100 Subject: [PATCH 1/2] push_commits: escape UTF-8 surrogates on errors when showing contents (bug 2023513) --- lando_cli/cli.py | 4 +++- tests/test_click.py | 10 +++++++++- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/lando_cli/cli.py b/lando_cli/cli.py index 137ff7a..06b84f6 100644 --- a/lando_cli/cli.py +++ b/lando_cli/cli.py @@ -373,7 +373,9 @@ def display_add_commit_actions( click.echo(f"About to push {len(actions)} commits.") # Use the last patch as the tip commit - last_patch = base64.b64decode(actions[-1]["content"]).decode("utf-8") + last_patch = base64.b64decode(actions[-1]["content"]).decode( + "utf-8", errors="surrogateescape" + ) first_line = last_patch.splitlines()[0] if first_line.startswith("From "): diff --git a/tests/test_click.py b/tests/test_click.py index 33b03fe..c996802 100644 --- a/tests/test_click.py +++ b/tests/test_click.py @@ -40,17 +40,25 @@ def mock_submit_to_lando(monkeypatch: pytest.MonkeyPatch) -> mock.Mock: return mock_fixture +@pytest.mark.parametrize( + "commit_data", + ( + "just a string", + b"-\x1f\x8b\n", # GZip magic bytes + ), +) def test_push_commits( git_local_repo: Path, create_commit: Callable, mock_get_repo_info: mock.Mock, mock_submit_to_lando: mock.Mock, + commit_data: str, ): commit_message = "New commit to push" runner = CliRunner() with runner.isolated_filesystem(git_local_repo): - create_commit(commit_message=commit_message) + create_commit(commit_data, commit_message=commit_message) result = runner.invoke(cli.push_commits, ["--yes"]) assert result.exit_code == 0 From 5e35fb446fe2a7db4be975437ad3b6d5c0a56a35 Mon Sep 17 00:00:00 2001 From: Olivier Mehani Date: Tue, 17 Mar 2026 12:42:11 +1100 Subject: [PATCH 2/2] Apply suggestion from @shtrom --- tests/test_click.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_click.py b/tests/test_click.py index c996802..3124f67 100644 --- a/tests/test_click.py +++ b/tests/test_click.py @@ -52,7 +52,7 @@ def test_push_commits( create_commit: Callable, mock_get_repo_info: mock.Mock, mock_submit_to_lando: mock.Mock, - commit_data: str, + commit_data: bytes | str, ): commit_message = "New commit to push"