diff --git a/src/RestSharp/Parameters/UrlSegmentParameter.cs b/src/RestSharp/Parameters/UrlSegmentParameter.cs index b9da7752a..c3c4ff98a 100644 --- a/src/RestSharp/Parameters/UrlSegmentParameter.cs +++ b/src/RestSharp/Parameters/UrlSegmentParameter.cs @@ -26,10 +26,11 @@ public partial record UrlSegmentParameter : NamedParameter { /// Parameter name /// Parameter value /// Optional: encode the value, default is true - public UrlSegmentParameter(string name, string value, bool encode = true) + /// Optional: whether to replace all %2f and %2F in the parameter value with '/', default is true + public UrlSegmentParameter(string name, string value, bool encode = true, bool replaceEncodedSlash = true) : base( name, - RegexPattern.Replace(Ensure.NotEmptyString(value, nameof(value)), "/"), + replaceEncodedSlash ? RegexPattern.Replace(Ensure.NotEmptyString(value, nameof(value)), "/") : value, ParameterType.UrlSegment, encode ) { } diff --git a/test/RestSharp.Tests/ParametersTests.cs b/test/RestSharp.Tests/ParametersTests.cs index e9c702fbc..b8807ed20 100644 --- a/test/RestSharp.Tests/ParametersTests.cs +++ b/test/RestSharp.Tests/ParametersTests.cs @@ -63,4 +63,28 @@ public void AddUrlSegmentModifiesUrlSegmentWithString() { expected.Should().BeEquivalentTo(actual); } + + [Theory] + [InlineData("bar%2fBAR")] + [InlineData("bar%2FBAR")] + public void UrlSegmentParameter_WithValueWithEncodedSlash_WillReplaceEncodedSlashByDefault(string inputValue) { + var urlSegmentParameter = new UrlSegmentParameter("foo", inputValue); + urlSegmentParameter.Value.Should().BeEquivalentTo("bar/BAR"); + } + + [Theory] + [InlineData("bar%2fBAR")] + [InlineData("bar%2FBAR")] + public void UrlSegmentParameter_WithValueWithEncodedSlash_CanReplaceEncodedSlash(string inputValue) { + var urlSegmentParameter = new UrlSegmentParameter("foo", inputValue, replaceEncodedSlash: true); + urlSegmentParameter.Value.Should().BeEquivalentTo("bar/BAR"); + } + + [Theory] + [InlineData("bar%2fBAR")] + [InlineData("bar%2FBAR")] + public void UrlSegmentParameter_WithValueWithEncodedSlash_CanLeaveEncodedSlash(string inputValue) { + var urlSegmentParameter = new UrlSegmentParameter("foo", inputValue, replaceEncodedSlash: false); + urlSegmentParameter.Value.Should().BeEquivalentTo(inputValue); + } } \ No newline at end of file