Skip to content

Commit ba2ebac

Browse files
committed
Merge branch 'dev' of github.com:finbourne/RestSharp into finbourne-dev
2 parents 25922ce + 3cbd7ad commit ba2ebac

File tree

2 files changed

+27
-2
lines changed

2 files changed

+27
-2
lines changed

src/RestSharp/Parameters/UrlSegmentParameter.cs

+3-2
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,11 @@ public partial record UrlSegmentParameter : NamedParameter {
2626
/// <param name="name">Parameter name</param>
2727
/// <param name="value">Parameter value</param>
2828
/// <param name="encode">Optional: encode the value, default is true</param>
29-
public UrlSegmentParameter(string name, string value, bool encode = true)
29+
/// <param name="replaceEncodedSlash">Optional: whether to replace all %2f and %2F in the parameter value with '/', default is true</param>
30+
public UrlSegmentParameter(string name, string value, bool encode = true, bool replaceEncodedSlash = true)
3031
: base(
3132
name,
32-
RegexPattern.Replace(Ensure.NotEmptyString(value, nameof(value)), "/"),
33+
replaceEncodedSlash ? RegexPattern.Replace(Ensure.NotEmptyString(value, nameof(value)), "/") : value,
3334
ParameterType.UrlSegment,
3435
encode
3536
) { }

test/RestSharp.Tests/ParametersTests.cs

+24
Original file line numberDiff line numberDiff line change
@@ -63,4 +63,28 @@ public void AddUrlSegmentModifiesUrlSegmentWithString() {
6363

6464
expected.Should().BeEquivalentTo(actual);
6565
}
66+
67+
[Theory]
68+
[InlineData("bar%2fBAR")]
69+
[InlineData("bar%2FBAR")]
70+
public void UrlSegmentParameter_WithValueWithEncodedSlash_WillReplaceEncodedSlashByDefault(string inputValue) {
71+
var urlSegmentParameter = new UrlSegmentParameter("foo", inputValue);
72+
urlSegmentParameter.Value.Should().BeEquivalentTo("bar/BAR");
73+
}
74+
75+
[Theory]
76+
[InlineData("bar%2fBAR")]
77+
[InlineData("bar%2FBAR")]
78+
public void UrlSegmentParameter_WithValueWithEncodedSlash_CanReplaceEncodedSlash(string inputValue) {
79+
var urlSegmentParameter = new UrlSegmentParameter("foo", inputValue, replaceEncodedSlash: true);
80+
urlSegmentParameter.Value.Should().BeEquivalentTo("bar/BAR");
81+
}
82+
83+
[Theory]
84+
[InlineData("bar%2fBAR")]
85+
[InlineData("bar%2FBAR")]
86+
public void UrlSegmentParameter_WithValueWithEncodedSlash_CanLeaveEncodedSlash(string inputValue) {
87+
var urlSegmentParameter = new UrlSegmentParameter("foo", inputValue, replaceEncodedSlash: false);
88+
urlSegmentParameter.Value.Should().BeEquivalentTo(inputValue);
89+
}
6690
}

0 commit comments

Comments
 (0)