Skip to content

fix(core): emit LF newlines for tsv output#33427

Open
rohan-patnaik wants to merge 2 commits into
Azure:devfrom
rohan-patnaik:fix-tsv-lf-newlines
Open

fix(core): emit LF newlines for tsv output#33427
rohan-patnaik wants to merge 2 commits into
Azure:devfrom
rohan-patnaik:fix-tsv-lf-newlines

Conversation

@rohan-patnaik
Copy link
Copy Markdown

Fixes #33385

Summary

This forces tsv output streams to use LF newlines before writing the formatted result.

Why

On Windows, Python text-mode output can translate \n into \r\n. That makes az ... -o tsv unsafe in bash-style command substitution because intermediate values keep a trailing \r, which can then break follow-up CLI calls.

Test plan

  • .venv/bin/python -m pytest src/azure-cli-core/azure/cli/core/tests/test_output.py
  • .venv/bin/python -m compileall -q src/azure-cli-core/azure/cli/core/_output.py src/azure-cli-core/azure/cli/core/tests/test_output.py
  • git diff --check

@azure-client-tools-bot-prd
Copy link
Copy Markdown

Validation for Azure CLI Full Test Starting...

Thanks for your contribution!

@azure-client-tools-bot-prd
Copy link
Copy Markdown

Hi @rohan-patnaik,
Since the current milestone time is less than 7 days, this pr will be reviewed in the next milestone.

@azure-client-tools-bot-prd
Copy link
Copy Markdown

Validation for Breaking Change Starting...

Thanks for your contribution!

@microsoft-github-policy-service microsoft-github-policy-service Bot added the customer-reported Issues that are reported by GitHub users external to the Azure organization. label May 22, 2026
@microsoft-github-policy-service
Copy link
Copy Markdown
Contributor

Thank you for your contribution @rohan-patnaik! We will review the pull request and get back to you soon.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Note

Copilot was unable to run its full agentic suite in this review.

Adds a TSV-specific behavior to force LF (\n) newlines during output, and introduces a regression test to ensure TSV output remains consistent across platforms (notably Windows).

Changes:

  • Add a regression test validating TSV output uses LF newlines even when the stream is configured for CRLF.
  • Override AzOutputProducer.out() to reconfigure the output stream newline handling when output format is tsv.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
src/azure-cli-core/azure/cli/core/tests/test_output.py Adds regression test asserting TSV output is LF-terminated.
src/azure-cli-core/azure/cli/core/_output.py Reconfigures output stream newline handling for TSV via out() override.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +16 to +21
def out(self, obj, formatter=None, out_file=None):
if get_output_format(self.cli_ctx) == "tsv":
file = out_file or sys.stdout
if hasattr(file, "reconfigure"):
file.reconfigure(newline="\n")
super().out(obj, formatter=formatter, out_file=out_file)
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Addressed in d523bf1: out() now returns super().out(...) and passes the reconfigured stream through as out_file=file.

@yonzhan
Copy link
Copy Markdown
Collaborator

yonzhan commented May 22, 2026

Thank you for your contribution! We will review the pull request and get back to you soon.

@github-actions
Copy link
Copy Markdown

The git hooks are available for azure-cli and azure-cli-extensions repos. They could help you run required checks before creating the PR.

Please sync the latest code with latest dev branch (for azure-cli) or main branch (for azure-cli-extensions).
After that please run the following commands to enable git hooks:

pip install azdev --upgrade
azdev setup -c <your azure-cli repo path> -r <your azure-cli-extensions repo path>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

act-platform-engineering-squad Auto-Assign Auto assign by bot Core CLI core infrastructure customer-reported Issues that are reported by GitHub users external to the Azure organization.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

-o tsv emits CRLF on Windows, breaking for x in $(az ... -o tsv) shell loops with misleading 400 errors

5 participants