From 6db6b1ad050d6b67f34693cfffd3eff441ffc8cd Mon Sep 17 00:00:00 2001 From: luissena Date: Fri, 20 Mar 2026 18:53:16 -0300 Subject: [PATCH] Validate channel format in dotnet-install.sh When an unsupported channel format is provided (e.g., `-c 10`), the script now exits early with a clear error message listing the supported formats (STS, LTS, A.B, A.B.Cxx) instead of proceeding to construct invalid URLs that fail with confusing 404 errors. Fixes dotnet/install-scripts#686 --- src/dotnet-install.sh | 12 ++++++++++-- .../GivenThatIWantToGetTheSdkLinksFromAScript.cs | 3 ++- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/src/dotnet-install.sh b/src/dotnet-install.sh index c44294628..597b99cc9 100644 --- a/src/dotnet-install.sh +++ b/src/dotnet-install.sh @@ -524,8 +524,16 @@ get_normalized_channel() { return 0 ;; *) - echo "$channel" - return 0 + if [[ "$channel" =~ ^[0-9]+\.[0-9]+$ ]]; then + echo "$channel" + return 0 + elif [[ "$channel" =~ ^[0-9]+\.[0-9]+\.[0-9]+[a-z]{2}$ ]]; then + echo "$channel" + return 0 + else + say_err "'$1' is not a supported value for --channel option. Supported values are: STS, LTS, a 2-part version in A.B format (e.g., 10.0), or a 3-part SDK band version in A.B.Cxx format (e.g., 5.0.1xx). If you think this is a bug, report it at https://github.com/dotnet/install-scripts/issues." + return 1 + fi ;; esac fi diff --git a/tests/Install-Scripts.Test/GivenThatIWantToGetTheSdkLinksFromAScript.cs b/tests/Install-Scripts.Test/GivenThatIWantToGetTheSdkLinksFromAScript.cs index 32e65ba12..34c5d1f2c 100644 --- a/tests/Install-Scripts.Test/GivenThatIWantToGetTheSdkLinksFromAScript.cs +++ b/tests/Install-Scripts.Test/GivenThatIWantToGetTheSdkLinksFromAScript.cs @@ -305,6 +305,7 @@ public void CanResolveCorrectLocationBasedOnVersion(string version, string locat [InlineData("release/2.6.1xx")] [InlineData("4.8.2")] [InlineData("abcdefg")] + [InlineData("10")] public void WhenInvalidChannelWasUsed(string channel) { string feedCredentials = Guid.NewGuid().ToString(); @@ -314,7 +315,7 @@ public void WhenInvalidChannelWasUsed(string channel) // Standard 'dryrun' criterion commandResult.Should().Fail(); - commandResult.Should().HaveStdErrContaining("Failed to resolve the exact version number."); + commandResult.Should().HaveStdErrContaining("is not a supported value for --channel option."); commandResult.Should().NotHaveStdOutContaining("Repeatable invocation:"); commandResult.Should().NotHaveStdOutContainingIgnoreCase(feedCredentials); commandResult.Should().NotHaveStdErrContainingIgnoreCase(feedCredentials);