Skip to content

Commit 675b06c

Browse files
committed
TypeFilter did not mark itself conditionless properly
1 parent 459ea50 commit 675b06c

File tree

5 files changed

+53
-18
lines changed

5 files changed

+53
-18
lines changed

src/Nest.Tests.Unit/Core/Get/GetFullTests.cs

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -41,16 +41,7 @@ public void GetUsingDescriptor()
4141
var status = result.ConnectionStatus;
4242
StringAssert.EndsWith("/myindex/elasticsearchprojects/404", status.RequestUrl);
4343
}
44-
[Test]
45-
public void GetUsingDescriptorEscapes()
46-
{
47-
var result = this._client.GetFull<ElasticSearchProject>(g => g
48-
.Index("myindex")
49-
.Id("myid/with/slashes")
50-
);
51-
var status = result.ConnectionStatus;
52-
StringAssert.EndsWith("/myindex/elasticsearchprojects/myid%252Fwith%252Fslashes", status.RequestUrl);
53-
}
44+
5445
[Test]
5546
public void GetUsingDescriptorWithType()
5647
{

src/Nest.Tests.Unit/Core/Index/IndexTests.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ public void IndexParameters()
2828
var status = result.ConnectionStatus;
2929
StringAssert.Contains("version=1", status.RequestUrl);
3030
}
31+
3132
[Test]
3233
public void GetSupportsVersioning()
3334
{

src/Nest/DSL/Filter/TypeFilter.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ internal override bool IsConditionless
1313
{
1414
get
1515
{
16-
return this.Value.IsNullOrEmpty();
16+
return this.Value.IsConditionless();
1717
}
1818

1919
}

src/Nest/Domain/Connection/Connection.cs

Lines changed: 43 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
using System.Collections.Specialized;
44
using System.IO;
55
using System.Net;
6+
using System.Reflection;
67
using System.Text;
78
using System.Threading;
89
using System.Threading.Tasks;
@@ -326,17 +327,21 @@ public void Iterate(IEnumerable<Task> asyncIterator, TaskCompletionSource<Connec
326327
recursiveBody(null);
327328
}
328329

329-
private string _CreateUriString(string path)
330+
private Uri _CreateUriString(string path)
330331
{
331332
var s = this._ConnectionSettings;
332-
333+
334+
333335
if (s.QueryStringParameters != null)
334336
{
335-
var uri = new Uri(s.Uri, path);
336-
var qs = s.QueryStringParameters.ToQueryString(uri.Query.IsNullOrEmpty() ? "?" : "&");
337+
var tempUri = new Uri(s.Uri, path);
338+
var qs = s.QueryStringParameters.ToQueryString(tempUri.Query.IsNullOrEmpty() ? "?" : "&");
337339
path += qs;
338340
}
339-
341+
LeaveDotsAndSlashesEscaped(s.Uri);
342+
var uri = new Uri(s.Uri, path);
343+
LeaveDotsAndSlashesEscaped(uri);
344+
return uri;
340345
var url = s.Uri.AbsoluteUri + path;
341346
//WebRequest.Create will replace %2F with /
342347
//this is a 'security feature'
@@ -346,7 +351,39 @@ private string _CreateUriString(string path)
346351
//it won't barf.
347352
//If you manually set the config settings to NOT forefully unescape dots and slashes be sure to call
348353
//.SetDontDoubleEscapePathDotsAndSlashes() on the connection settings.
349-
return this._ConnectionSettings.DontDoubleEscapePathDotsAndSlashes ? url : url.Replace("%2F", "%252F");
354+
//return );
355+
356+
//return this._ConnectionSettings.DontDoubleEscapePathDotsAndSlashes ? url : url.Replace("%2F", "%252F");
357+
}
358+
359+
// System.UriSyntaxFlags is internal, so let's duplicate the flag privately
360+
private const int UnEscapeDotsAndSlashes = 0x2000000;
361+
362+
public static void LeaveDotsAndSlashesEscaped(Uri uri)
363+
{
364+
if (uri == null)
365+
{
366+
throw new ArgumentNullException("uri");
367+
}
368+
369+
FieldInfo fieldInfo = uri.GetType().GetField("m_Syntax", BindingFlags.Instance | BindingFlags.NonPublic);
370+
if (fieldInfo == null)
371+
{
372+
throw new MissingFieldException("'m_Syntax' field not found");
373+
}
374+
object uriParser = fieldInfo.GetValue(uri);
375+
376+
fieldInfo = typeof(UriParser).GetField("m_Flags", BindingFlags.Instance | BindingFlags.NonPublic);
377+
if (fieldInfo == null)
378+
{
379+
throw new MissingFieldException("'m_Flags' field not found");
380+
}
381+
object uriSyntaxFlags = fieldInfo.GetValue(uriParser);
382+
383+
// Clear the flag that we don't want
384+
uriSyntaxFlags = (int)uriSyntaxFlags & ~UnEscapeDotsAndSlashes;
385+
386+
fieldInfo.SetValue(uriParser, uriSyntaxFlags);
350387
}
351388
}
352389
}

src/Nest/Resolvers/TypeNameMarker.cs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,12 @@ public class TypeNameMarker : IEquatable<TypeNameMarker>
1010
public string Name { get; set; }
1111
public Type Type { get; set; }
1212

13+
public bool IsConditionless ()
14+
{
15+
return this.Name.IsNullOrEmpty() && this.Type == null;
16+
}
17+
18+
1319
public string Resolve(IConnectionSettings connectionSettings)
1420
{
1521
connectionSettings.ThrowIfNull("connectionSettings");
@@ -38,12 +44,12 @@ public static implicit operator TypeNameMarker(string typeName)
3844
{
3945
return new TypeNameMarker {Name = typeName};
4046
}
47+
4148
public static implicit operator TypeNameMarker(Type type)
4249
{
4350
return new TypeNameMarker { Type = type };
4451
}
4552

46-
4753
public override int GetHashCode()
4854
{
4955
if (this.Name != null)

0 commit comments

Comments
 (0)