From b980954ebb29f341b8d92d56e12b4640c49fbefb Mon Sep 17 00:00:00 2001 From: El <41842967+undef-i@users.noreply.github.com> Date: Fri, 1 Nov 2024 05:44:45 +0800 Subject: [PATCH] Fix Errors in PowerShell Code in Flutter Setup Guide for China (#11329) ### Page Source Code Location `src/_includes/docs/community/china/os-settings.md` https://docs.flutter.dev/community/china ### Problem Description The code in the documentation is attempting to set environment variables for Flutter but contains errors that lead to unexpected behavior. #### Incorrect Code ```powershell newPath = $pwd.PATH + "/flutter/bin",$env:PATH -join ";" [System.Environment]::SetEnvironmentVariable('Path',$newPath,User) [System.Environment]::SetEnvironmentVariable('PUB_HOSTED_URL','https://pub.flutter-io.cn',User) [System.Environment]::SetEnvironmentVariable('FLUTTER_STORAGE_BASE_URL','https://storage.flutter-io.cn',User) ``` #### Issues Identified: 1. **Incorrect Path Concatenation**: The variable `newPath` concatenates using a comma, which results in incorrect setting of the PATH environment variable. - **Expected `newPath` (example)**: `C:\Users\User\flutter\bin;C:\Windows` - **Actual Value of `newPath`**: `C:\Users\User/flutter/bin C:\Windows` 2. **Missing Quotes for 'User'**: The `User` parameter in `SetEnvironmentVariable` method calls is not enclosed in quotes, leading to runtime exceptions. ```plaintext + [System.Environment]::SetEnvironmentVariable('Path',$newPath,User) + ~ Missing expression after ','. At line:1 char:62 + [System.Environment]::SetEnvironmentVariable('Path',$newPath,User) + ~~~~ Unexpected token 'User' in expression or statement. At line:1 char:66 + [System.Environment]::SetEnvironmentVariable('Path',$newPath,User) + ~ Unexpected token ')' in expression or statement. + CategoryInfo : ParserError: (:) [], ParentContainsErrorRecordException + FullyQualifiedErrorId : MissingExpressionAfterToken ``` Co-authored-by: Brett Morgan --- src/_includes/docs/community/china/os-settings.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/_includes/docs/community/china/os-settings.md b/src/_includes/docs/community/china/os-settings.md index c458f9e3b4..2ad9742f70 100644 --- a/src/_includes/docs/community/china/os-settings.md +++ b/src/_includes/docs/community/china/os-settings.md @@ -13,10 +13,10 @@ {% capture newdir -%}{{prompt}} New-Item -Path '{{installdirsuggestion}}' -ItemType Directory{% endcapture -%} {% capture unzip -%} {{prompt}} Expand-Archive .\{% endcapture -%} {% capture permaddexample -%} -$newPath = $pwd.PATH + "/flutter/bin",$env:PATH -join ";" -[System.Environment]::SetEnvironmentVariable('Path',$newPath,User) -[System.Environment]::SetEnvironmentVariable('PUB_HOSTED_URL','https://pub.flutter-io.cn',User) -[System.Environment]::SetEnvironmentVariable('FLUTTER_STORAGE_BASE_URL','https://storage.flutter-io.cn',User) +$newPath = "$pwd\flutter\bin;$env:PATH" +[System.Environment]::SetEnvironmentVariable('Path', $newPath, 'User') +[System.Environment]::SetEnvironmentVariable('PUB_HOSTED_URL', 'https://pub.flutter-io.cn', 'User') +[System.Environment]::SetEnvironmentVariable('FLUTTER_STORAGE_BASE_URL', 'https://storage.flutter-io.cn', 'User') {% endcapture -%} {% else -%} {% assign shell = 'your terminal' -%}