Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft PR - nextlink encode #2199

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions src/Microsoft.AspNet.OData.Shared/GetNextPageHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using System.Diagnostics.Contracts;
using System.Globalization;
using System.Text;
using System.Web;

namespace Microsoft.AspNet.OData
{
Expand All @@ -14,7 +15,7 @@ namespace Microsoft.AspNet.OData
/// </summary>
internal static partial class GetNextPageHelper
{
internal static Uri GetNextPageLink(Uri requestUri, IEnumerable<KeyValuePair<string, string>> queryParameters, int pageSize, object instance = null, Func<object, string> objectToSkipTokenValue = null, CompatibilityOptions options = CompatibilityOptions.None)
internal static Uri GetNextPageLink(Uri requestUri, IEnumerable<KeyValuePair<string, string>> queryParameters, int pageSize, object instance = null, Func<object, string> objectToSkipTokenValue = null, CompatibilityOptions options = CompatibilityOptions.None, bool encodeUrl = false)
{
Contract.Assert(requestUri != null);
Contract.Assert(queryParameters != null);
Expand Down Expand Up @@ -96,7 +97,7 @@ internal static Uri GetNextPageLink(Uri requestUri, IEnumerable<KeyValuePair<str

UriBuilder uriBuilder = new UriBuilder(requestUri)
{
Query = queryBuilder.ToString()
Query = encodeUrl? HttpUtility.UrlEncode( queryBuilder.ToString()): queryBuilder.ToString()
};

return uriBuilder.Uri;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,9 @@ internal interface IWebApiRequestMessage
/// <param name="pageSize">The page size.</param>
/// <param name="instance">The instance based on which the skiptoken value is generated</param>
/// <param name="objToSkipTokenValue">Function that takes in the last object and returns the skiptoken value string.</param>
/// <param name="encodeUrl">Optional Parameter to determine whether the nextpace url should be encoded.</param>
/// <returns></returns>
Uri GetNextPageLink(int pageSize, object instance, Func<object, string> objToSkipTokenValue);
Uri GetNextPageLink(int pageSize, object instance, Func<object, string> objToSkipTokenValue,bool encodeUrl);

/// <summary>
/// Get a list of content Id mappings associated with the request.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ public override Uri GenerateNextPageLink(Uri baseUri, int pageSize, Object insta
return GenerateSkipTokenValue(obj, model, orderByNodes);
};

return GetNextPageHelper.GetNextPageLink(baseUri, pageSize, instance, skipTokenGenerator);
return GetNextPageHelper.GetNextPageLink(baseUri, pageSize, instance, skipTokenGenerator,encodeUrl:true);
}

if (context.QueryOptions != null && context.QueryOptions.OrderBy != null)
Expand All @@ -86,7 +86,7 @@ public override Uri GenerateNextPageLink(Uri baseUri, int pageSize, Object insta
};
}

return context.InternalRequest.GetNextPageLink(pageSize, instance, skipTokenGenerator);
return context.InternalRequest.GetNextPageLink(pageSize, instance, skipTokenGenerator, encodeUrl: true);
}

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,10 +138,11 @@ public ODataDeserializerProvider DeserializerProvider
/// <param name="pageSize">The page size.</param>
/// <param name="instance">Object which will be used to generate the skiptoken value.</param>
/// <param name="objToSkipTokenValue">Function that takes in an instance and returns the skiptoken value string.</param>
/// <param name="encodeUrl">Optional Parameter to determine whether the nextpace url should be encoded.</param>
/// <returns></returns>
public Uri GetNextPageLink(int pageSize, object instance = null, Func<object, string> objToSkipTokenValue = null)
public Uri GetNextPageLink(int pageSize, object instance = null, Func<object, string> objToSkipTokenValue = null,bool encodeUrl =false)
{
return this.innerRequest.GetNextPageLink(pageSize, instance, objToSkipTokenValue);
return this.innerRequest.GetNextPageLink(pageSize, instance, objToSkipTokenValue,encodeUrl:encodeUrl);
}

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -263,10 +263,11 @@ public static ETag<TEntity> GetETag<TEntity>(this HttpRequest request, EntityTag
/// </summary>
/// <param name="request">The request on which to base the next page link.</param>
/// <param name="pageSize">The number of results allowed per page.</param>
/// <param name="encodeUrl">Optional Parameter to determine whether the nextpace url should be encoded.</param>
/// <returns>A next page link.</returns>
public static Uri GetNextPageLink(this HttpRequest request, int pageSize)
public static Uri GetNextPageLink(this HttpRequest request, int pageSize,bool encodeUrl =false)
{
return GetNextPageLink(request, pageSize, null, null);
return GetNextPageLink(request, pageSize, null, null);
}

/// <summary>
Expand All @@ -276,8 +277,9 @@ public static Uri GetNextPageLink(this HttpRequest request, int pageSize)
/// <param name="pageSize">The number of results allowed per page.</param>
/// <param name="instance">Object which can be used to generate the skiptoken value.</param>
/// <param name="objectToSkipTokenValue">Function that takes in the last object and returns the skiptoken value string.</param>
/// <param name="encodeUrl">Optional Parameter to determine whether the nextpace url should be encoded.</param>
/// <returns>A next page link.</returns>
public static Uri GetNextPageLink(this HttpRequest request, int pageSize, object instance, Func<object,string> objectToSkipTokenValue)
public static Uri GetNextPageLink(this HttpRequest request, int pageSize, object instance, Func<object,string> objectToSkipTokenValue, bool encodeUrl = false)
{
if (request == null)
{
Expand Down
4 changes: 2 additions & 2 deletions src/Microsoft.AspNetCore.OData/GetNextPageHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,15 @@ namespace Microsoft.AspNet.OData
internal static partial class GetNextPageHelper
{
/// <remarks>This signature uses types that are AspNetCore-specific.</remarks>
internal static Uri GetNextPageLink(Uri requestUri, int pageSize, object instance = null, Func<object, String> objectToSkipTokenValue = null)
internal static Uri GetNextPageLink(Uri requestUri, int pageSize, object instance = null, Func<object, String> objectToSkipTokenValue = null, bool encodeUrl =false)
{
Contract.Assert(requestUri != null);

Dictionary<string, StringValues> queryValues = QueryHelpers.ParseQuery(requestUri.Query);
IEnumerable<KeyValuePair<string, string>> queryParameters = queryValues.SelectMany(
kvp => kvp.Value, (kvp, value) => new KeyValuePair<string, string>(kvp.Key, value));

return GetNextPageLink(requestUri, queryParameters, pageSize, instance, objectToSkipTokenValue);
return GetNextPageLink(requestUri, queryParameters, pageSize, instance, objectToSkipTokenValue,encodeUrl:encodeUrl);
}
}
}