Skip to content

Commit

Permalink
Merge branch 'dev' of github.com:finbourne/RestSharp into finbourne-dev
Browse files Browse the repository at this point in the history
  • Loading branch information
alexeyzimarev committed Dec 17, 2024
2 parents 25922ce + 3cbd7ad commit ba2ebac
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/RestSharp/Parameters/UrlSegmentParameter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,11 @@ public partial record UrlSegmentParameter : NamedParameter {
/// <param name="name">Parameter name</param>
/// <param name="value">Parameter value</param>
/// <param name="encode">Optional: encode the value, default is true</param>
public UrlSegmentParameter(string name, string value, bool encode = true)
/// <param name="replaceEncodedSlash">Optional: whether to replace all %2f and %2F in the parameter value with '/', default is true</param>
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
) { }
Expand Down
24 changes: 24 additions & 0 deletions test/RestSharp.Tests/ParametersTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

0 comments on commit ba2ebac

Please sign in to comment.