-
Notifications
You must be signed in to change notification settings - Fork 8.1k
Description
Prerequisites
- Write a descriptive title.
- Make sure you are able to repro it on the latest released version
- Search the existing issues.
- Refer to the FAQ.
- Refer to Differences between Windows PowerShell 5.1 and PowerShell.
Steps to reproduce
After discuss with Copilot, Copilot strongly suggest to report the following issue.
The following contents and wordings are all create by Copilot, not by me. I'm just a beginner on coding, can not understand most of it.
Summary
When a PowerShell script (.ps1) is saved with UTF‑8 with BOM, stored under a OneDrive path, and the filename contains Chinese characters, PowerShell fails to parse the script and throws errors such as:
MissingEndCurlyBrace
Try statement is missing catch or finally block
Unexpected token 'finally'
Missing '}' in statement block
The same script works perfectly when:
The file is renamed to an English filename, or
The file is saved as UTF‑8 (without BOM), or
The file is moved outside OneDrive, or
The script is run inside VS Code (VS Code analyzer does not detect any syntax errors)
This indicates a parser bug triggered by the combination of:
UTF‑8 BOM
OneDrive path
Chinese filename
PowerShell parser behavior
Environment
Windows 11
PowerShell 7.x
VS Code latest version
Script stored under:
C:\Users<user>\OneDrive\VS Code\中文檔名.ps1
Script encoding: UTF‑8 with BOM (VS Code default for Chinese filenames)
Steps to Reproduce
Create a PowerShell script with valid syntax, for example:
powershell
try {
Write-Host "Hello"
} catch {
Write-Host "Error"
}
Save the file as:
測試腳本.ps1
Save the file under a OneDrive folder:
C:\Users<user>\OneDrive\VS Code\測試腳本.ps1
Ensure VS Code saves the file as UTF‑8 with BOM
Run the script:
powershell
.\測試腳本.ps1
Expected Behavior
PowerShell should execute the script normally.
Actual Behavior
PowerShell throws parser errors:
程式碼
MissingEndCurlyBrace
Try statement is missing catch or finally block
Unexpected token 'finally'
Even though the script is syntactically correct.
Workarounds
The script works if:
Renamed to English filename
Saved as UTF‑8 (without BOM)
Moved outside OneDrive
Executed inside VS Code terminal
Conclusion
This appears to be a parser bug triggered by BOM + OneDrive + Chinese filename.
It causes PowerShell to misinterpret the script and break the syntax tree.
Please investigate and fix in future PowerShell releases.
Expected behavior
PowerShell should execute the script normally.Actual behavior
PowerShell throws parser errors:
MissingEndCurlyBrace
Try statement is missing catch or finally block
Unexpected token 'finally'
Even though the script is syntactically correct.Error details
Workarounds
The script works if:
Renamed to English filename
Saved as UTF‑8 (without BOM)
Moved outside OneDrive
Executed inside VS Code terminal
Conclusion
This appears to be a parser bug triggered by BOM + OneDrive + Chinese filename.
It causes PowerShell to misinterpret the script and break the syntax tree.
Please investigate and fix in future PowerShell releases.Environment data
Environment
Windows 11
PowerShell 7.x
VS Code latest version
Script stored under:
C:\Users\<user>\OneDrive\VS Code\中文檔名.ps1
Script encoding: UTF‑8 with BOM (VS Code default for Chinese filenames)Visuals
