-
Notifications
You must be signed in to change notification settings - Fork 11k
fix: replace non-ASCII chars in PowerShell scripts for PS 5.1 compat #2708
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,54 @@ | ||
| """Regression tests for PowerShell 5.1 compatibility (GitHub issue #2680). | ||
|
|
||
| PowerShell 5.1 (built-in on Windows) defaults to the system's legacy encoding | ||
| when reading .ps1 files. Non-ASCII characters in UTF-8-encoded scripts cause | ||
| parse errors because multi-byte sequences are misinterpreted as individual bytes. | ||
|
|
||
| These tests ensure that all shipped .ps1 files remain ASCII-only so they work | ||
| on both PowerShell 5.1 and 7+. | ||
| """ | ||
|
|
||
| from pathlib import Path | ||
|
|
||
| import pytest | ||
|
|
||
| REPO_ROOT = Path(__file__).resolve().parent.parent | ||
|
|
||
| # All directories that contain shipped PowerShell scripts. | ||
| _PS1_DIRS = [ | ||
| REPO_ROOT / "scripts" / "powershell", | ||
| REPO_ROOT / "extensions" / "git" / "scripts" / "powershell", | ||
| ] | ||
|
|
||
|
|
||
| def _collect_ps1_files(): | ||
| """Yield all .ps1 files under the known script directories.""" | ||
| for d in _PS1_DIRS: | ||
| if d.is_dir(): | ||
| yield from sorted(d.glob("*.ps1")) | ||
|
mnriem marked this conversation as resolved.
|
||
|
|
||
|
|
||
| _PS1_FILES = list(_collect_ps1_files()) | ||
|
|
||
|
|
||
| @pytest.mark.parametrize("ps1_file", _PS1_FILES, ids=lambda p: str(p.relative_to(REPO_ROOT))) | ||
| def test_ps1_file_is_ascii_only(ps1_file: Path): | ||
| """Every .ps1 file must contain only ASCII characters (PS 5.1 compat).""" | ||
| content = ps1_file.read_bytes() | ||
| non_ascii = [ | ||
| (i + 1, byte) | ||
| for i, byte in enumerate(content) | ||
| if byte > 127 | ||
|
mnriem marked this conversation as resolved.
|
||
| ] | ||
| assert not non_ascii, ( | ||
| f"{ps1_file.relative_to(REPO_ROOT)} contains non-ASCII bytes " | ||
| f"(PowerShell 5.1 incompatible): " | ||
| f"first at byte offset {non_ascii[0][0]} (0x{non_ascii[0][1]:02x})" | ||
| ) | ||
|
|
||
|
|
||
| def test_ps1_files_discovered(): | ||
| """Sanity check: at least the known script files are found.""" | ||
| names = {p.name for p in _PS1_FILES} | ||
| assert "common.ps1" in names | ||
| assert "initialize-repo.ps1" in names | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.