Skip to content

Commit

Permalink
Fixed a search bug to properly encode parameters.
Browse files Browse the repository at this point in the history
  • Loading branch information
JoeMayo committed Dec 17, 2017
1 parent 0981dfc commit 1738c38
Show file tree
Hide file tree
Showing 7 changed files with 29 additions and 161 deletions.
3 changes: 1 addition & 2 deletions Samples/net46/CSharp/ConsoleSamples/SearchDemos.cs
Expand Up @@ -53,8 +53,7 @@ static void ShowMenu()

static async Task DoSearchAsync(TwitterContext twitterCtx)
{
string searchTerm = "\"LINQ to Twitter\" OR Linq2Twitter OR LinqToTwitter OR JoeMayo :)";
//string searchTerm = "#ömer -RT -instagram news source%3Afoursquare";
string searchTerm = "\"LINQ to Twitter\" OR Linq2Twitter OR LinqToTwitter OR JoeMayo";

Search searchResponse =
await
Expand Down
@@ -1,6 +1,4 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Collections.Generic;
using System.Net;
using System.Net.Http;
using System.Threading;
Expand Down Expand Up @@ -31,9 +29,6 @@ protected async override Task<HttpResponseMessage> SendAsync(HttpRequestMessage
if (exe.Authorizer.Proxy != null && SupportsProxy)
Proxy = exe.Authorizer.Proxy;

//if (exe.ReadWriteTimeout != 0)
// ReadWriteTimeout = exe.ReadWriteTimeout;

return await base.SendAsync(request, cancellationToken).ConfigureAwait(false);
}
}
Expand Down
34 changes: 26 additions & 8 deletions src/LinqToTwitter/LinqToTwitter.Shared/Common/Request.cs
@@ -1,4 +1,7 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace LinqToTwitter
{
Expand All @@ -7,12 +10,10 @@ public class Request
public string Endpoint { get; set; }
public IList<QueryParameter> RequestParameters { get; internal set; }

public string QueryString
public Request(string endpoint)
{
get
{
return Utilities.BuildQueryString(RequestParameters);
}
this.Endpoint = endpoint;
this.RequestParameters = new List<QueryParameter>();
}

public string FullUrl
Expand All @@ -27,10 +28,27 @@ public string FullUrl
}
}

public Request(string endpoint)
public string QueryString
{
this.Endpoint = endpoint;
this.RequestParameters = new List<QueryParameter>();
get
{
if (RequestParameters == null)
throw new ArgumentNullException("parameters");

StringBuilder builder = new StringBuilder();
foreach (var pair in RequestParameters.Where(p => !string.IsNullOrWhiteSpace(p.Value)))
{
builder.Append(Uri.EscapeUriString(pair.Name));
builder.Append('=');
builder.Append(Uri.EscapeUriString(pair.Value));
builder.Append('&');
}

if (builder.Length > 1)
builder.Length--; // truncate trailing &

return builder.ToString();
}
}
}
}
137 changes: 0 additions & 137 deletions src/LinqToTwitter/LinqToTwitter.Shared/Common/Utilities.cs

This file was deleted.

Expand Up @@ -61,7 +61,6 @@
<Compile Include="$(MSBuildThisFileDirectory)Common\TwitterProgressEventArgs.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Common\TypeConversionExtensions.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Common\TypeSystem.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Common\Utilities.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Common\WhereClauseFinder.cs" />
<Compile Include="$(MSBuildThisFileDirectory)DirectMessageEvents\DirectMessageEvents.cs" />
<Compile Include="$(MSBuildThisFileDirectory)DirectMessageEvents\DirectMessageEventsRequestProcessor.cs" />
Expand Down
Expand Up @@ -79,15 +79,9 @@ public object Execute(Expression expression)
{
Type elementType = TypeSystem.GetElementType(expression.Type);

//#if NETFX_CORE
return GetType().GetTypeInfo()
.DeclaredMethods.Where(meth => meth.IsGenericMethod && meth.Name == "Execute").First()
.Invoke(this, new object[] { expression });
//#else
// return GetType()
// .GetMethod("Execute", new[] { elementType })
// .Invoke(this, new object[] { expression });
//#endif
}

/// <summary>
Expand Down
2 changes: 1 addition & 1 deletion src/LinqToTwitter/LinqToTwitter.Shared/Security/OAuth.cs
Expand Up @@ -45,7 +45,7 @@ internal string BuildEncodedSortedString(IDictionary<string, string> parameters)
string.Join("&",
(from parm in parameters
orderby parm.Key
select parm.Key + "=" + Url.PercentEncode(parameters[parm.Key]))
select parm.Key + "=" + Uri.EscapeUriString(parameters[parm.Key]))
.ToArray());
}

Expand Down

0 comments on commit 1738c38

Please sign in to comment.