Skip to content

Commit dbc147d

Browse files
committed
fix #1799, needed to go deeper to make sure we properly encode again
1 parent f6fd5e9 commit dbc147d

File tree

7 files changed

+44
-6
lines changed

7 files changed

+44
-6
lines changed

src/Elasticsearch.Net/Extensions/NameValueCollectionExtensions.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,8 @@ internal static string ToQueryString(this NameValueCollection self, string prefi
2626
return prefix + string.Join("&", self.AllKeys.Select(key => $"{Encode(key)}={Encode(self[key])}"));
2727
}
2828

29-
private static string Encode(string s) => s == null ? null : Uri.EscapeDataString(s);
29+
private static string Encode(string s) => s;
30+
//private static string Encode(string s) => s == null ? null : Uri.EscapeDataString(s);
3031

3132
internal static NameValueCollection ToNameValueCollection(this IDictionary<string, object> dict, IFormatProvider provider)
3233
{

src/Elasticsearch.Net/Serialization/UrlFormatProvider.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ public string Format(string format, object arg, IFormatProvider formatProvider)
2121
throw new ArgumentNullException();
2222
if (format == "r")
2323
return arg.ToString();
24-
return this.GetStringValue(arg);
24+
return Uri.EscapeDataString(this.GetStringValue(arg));
2525
}
2626

2727
public string GetStringValue(object valueType)

src/Nest/CommonAbstractions/Request/RouteValues.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ public void Resolve(IConnectionSettingsValues settings)
4949
foreach (var kv in _routeValues)
5050
{
5151
var key = kv.Value.GetString(settings);
52-
this._resolved[kv.Key] = key.IsNullOrEmpty() ?key : Uri.EscapeDataString(key);
52+
this._resolved[kv.Key] = key.IsNullOrEmpty() ? key : key;
5353
}
5454
}
5555

src/Tests/Document/Single/Get/GetApiTests.cs

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,33 @@ protected override void ExpectResponse(IGetResponse<Project> response)
4343
}
4444
}
4545

46+
[Collection(IntegrationContext.ReadOnly)]
47+
public class GetApiLowLevelTests : GetApiTests
48+
{
49+
public GetApiLowLevelTests(ReadOnlyCluster cluster, EndpointUsage usage) : base(cluster, usage) { }
50+
51+
protected override string UrlPath => $"/project/project/{ProjectIdForUrl}?fields=name%2CnumberOfCommits";
52+
53+
protected override LazyResponses ClientUsage() => Calls(
54+
fluent: (client, f) => client.Raw.Get<GetResponse<Project>>("project", "project", this.ProjectId, RequestParameter).Body,
55+
fluentAsync: (client, f) => client.Raw.GetAsync<GetResponse<Project>>("project", "project", this.ProjectId, RequestParameter)
56+
.ContinueWith<IGetResponse<Project>>(t=>t.Result.Body),
57+
request: (client, f) => client.Raw.Get<GetResponse<Project>>("project", "project", this.ProjectId, RequestParameter).Body,
58+
requestAsync: (client, f) => client.Raw.GetAsync<GetResponse<Project>>("project", "project", this.ProjectId, RequestParameter)
59+
.ContinueWith<IGetResponse<Project>>(t=>t.Result.Body)
60+
);
61+
62+
private GetRequestParameters RequestParameter(GetRequestParameters r) => r
63+
.Fields("name", "numberOfCommits");
64+
65+
protected override void ExpectResponse(IGetResponse<Project> response)
66+
{
67+
response.Fields.Should().NotBeNull();
68+
response.Fields.ValueOf<Project, string>(p => p.Name).Should().Be(ProjectId);
69+
response.Fields.ValueOf<Project, int?>(p => p.NumberOfCommits).Should().BeGreaterThan(0);
70+
}
71+
}
72+
4673
[Collection(IntegrationContext.ReadOnly)]
4774
public class GetApiFieldsTests : GetApiTests
4875
{

src/Tests/Document/Single/Get/GetUrlTests.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,10 @@ await GET($"/project/project/{escaped}?routing={escaped}")
4444
.FluentAsync(c => c.GetAsync<Project>(urlId, s=>s.Routing(urlId)))
4545
.RequestAsync(c => c.GetAsync<Project>(new GetRequest<Project>(urlId) { Routing = urlId }))
4646
;
47+
48+
GET($"/project/project/{escaped}?routing={escaped}")
49+
.LowLevel(c => c.Get<dynamic>("project", "project", urlId, s=>s.Routing(urlId)))
50+
;
4751
}
4852
}
4953
}

src/Tests/Framework/UrlTests.cs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,12 +47,17 @@ public UrlTester Request<TResponse>(Func<IElasticClient, TResponse> call)
4747
public Task<UrlTester> RequestAsync<TResponse>(Func<IElasticClient, Task<TResponse>> call)
4848
where TResponse : IResponse => WhenCallingAsync(call, "request async");
4949

50+
public UrlTester LowLevel(Func<IElasticsearchClient, IApiCallDetails> call)
51+
{
52+
var callDetails = call(this.GetClient().Raw);
53+
return Assert("lowleve", callDetails);
54+
}
5055

5156
internal UrlTester WhenCalling<TResponse>(Func<IElasticClient, TResponse> call, string typeOfCall)
5257
where TResponse : IResponse
5358
{
54-
var callDetails = call(this.GetClient()).CallDetails;
55-
return Assert(typeOfCall, callDetails);
59+
var callDetails = call(this.GetClient());
60+
return Assert(typeOfCall, callDetails.CallDetails);
5661
}
5762

5863
internal async Task<UrlTester> WhenCallingAsync<TResponse>(Func<IElasticClient, Task<TResponse>> call, string typeOfCall)

src/Tests/tests.yaml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# mode either u (unit test), i (integration test) or m (mixed mode)
2-
mode: u# the elasticsearch version that should be started
2+
mode: m
3+
# the elasticsearch version that should be started
34
elasticsearch_version: 2.0.1
45
# whether we want to forcefully reseed on the node, if you are starting the tests with a node already running
56
force_reseed: true

0 commit comments

Comments
 (0)