From 67907ea81b283c52c3b1b10a775617399b56052a Mon Sep 17 00:00:00 2001 From: Nesc58 Date: Fri, 4 Sep 2020 17:06:32 +0200 Subject: [PATCH] Use given culture or invariant culture when converting strings to lower or upper --- .../Authenticators/OAuth/Extensions/OAuthExtensions.cs | 2 +- src/RestSharp/Authenticators/OAuth/OAuthTools.cs | 2 +- src/RestSharp/Http.cs | 4 ++-- src/RestSharp/RestClient.cs | 6 +++--- src/RestSharp/Serializers/SerializeAsAttribute.cs | 2 +- src/RestSharp/Serializers/Xml/XmlDeserializer.cs | 10 +++++----- 6 files changed, 13 insertions(+), 13 deletions(-) diff --git a/src/RestSharp/Authenticators/OAuth/Extensions/OAuthExtensions.cs b/src/RestSharp/Authenticators/OAuth/Extensions/OAuthExtensions.cs index dcef8ddea..bd9a64739 100644 --- a/src/RestSharp/Authenticators/OAuth/Extensions/OAuthExtensions.cs +++ b/src/RestSharp/Authenticators/OAuth/Extensions/OAuthExtensions.cs @@ -22,7 +22,7 @@ internal static class OAuthExtensions { public static string ToRequestValue(this OAuthSignatureMethod signatureMethod) { - var value = signatureMethod.ToString().ToUpper(); + var value = signatureMethod.ToString().ToUpperInvariant(); var shaIndex = value.IndexOf("SHA", StringComparison.Ordinal); return shaIndex > -1 ? value.Insert(shaIndex, "-") : value; diff --git a/src/RestSharp/Authenticators/OAuth/OAuthTools.cs b/src/RestSharp/Authenticators/OAuth/OAuthTools.cs index de1f083e8..9fa723f8b 100644 --- a/src/RestSharp/Authenticators/OAuth/OAuthTools.cs +++ b/src/RestSharp/Authenticators/OAuth/OAuthTools.cs @@ -191,7 +191,7 @@ static string ConstructRequestUrl(Uri url) public static string ConcatenateRequestElements(string method, string url, WebPairCollection parameters) { // Separating &'s are not URL encoded - var requestMethod = method.ToUpper().Then("&"); + var requestMethod = method.ToUpperInvariant().Then("&"); var requestUrl = UrlEncodeRelaxed(ConstructRequestUrl(url.AsUri())).Then("&"); var requestParameters = UrlEncodeRelaxed(NormalizeRequestParameters(parameters)); diff --git a/src/RestSharp/Http.cs b/src/RestSharp/Http.cs index ca7511f58..44b86bf57 100644 --- a/src/RestSharp/Http.cs +++ b/src/RestSharp/Http.cs @@ -36,7 +36,7 @@ public partial class Http : IHttp { const string LineBreak = "\r\n"; - public string FormBoundary { get; } = "---------" + Guid.NewGuid().ToString().ToUpper(); + public string FormBoundary { get; } = "---------" + Guid.NewGuid().ToString().ToUpperInvariant(); // ReSharper disable once PrivateFieldCanBeConvertedToLocalVariable static readonly Regex AddRangeRegex = new Regex("(\\w+)=(\\d+)-(\\d+)$"); @@ -53,7 +53,7 @@ public Http() void AddSyncHeaderActions() { - _restrictedHeaderActions.Add("Connection", (r, v) => { r.KeepAlive = v.ToLower().Contains("keep-alive"); }); + _restrictedHeaderActions.Add("Connection", (r, v) => { r.KeepAlive = v.ToLowerInvariant().Contains("keep-alive"); }); _restrictedHeaderActions.Add("Content-Length", (r, v) => r.ContentLength = Convert.ToInt64(v)); _restrictedHeaderActions.Add("Expect", (r, v) => r.Expect = v); diff --git a/src/RestSharp/RestClient.cs b/src/RestSharp/RestClient.cs index 408c3f8d2..0a83f1a6e 100644 --- a/src/RestSharp/RestClient.cs +++ b/src/RestSharp/RestClient.cs @@ -268,7 +268,7 @@ void AddHandler(Func deserializerFactory, params string[] content void DoBuildUriValidations(IRestRequest request) { - if (BaseUrl == null && !request.Resource.ToLower().StartsWith("http")) + if (BaseUrl == null && !request.Resource.ToLowerInvariant().StartsWith("http")) throw new ArgumentOutOfRangeException( nameof(request), "Request resource doesn't contain a valid scheme for an empty client base URL" @@ -547,8 +547,8 @@ IRestResponse Deserialize(IRestRequest request, IRestResponse raw) response = raw.ToAsyncResponse(); // Only attempt to deserialize if the request has not errored due - // to a transport or framework exception. HTTP errors should attempt to - // be deserialized + // to a transport or framework exception. HTTP errors should attempt to + // be deserialized if (response.ErrorException == null) { var func = GetHandler(raw.ContentType); diff --git a/src/RestSharp/Serializers/SerializeAsAttribute.cs b/src/RestSharp/Serializers/SerializeAsAttribute.cs index 3508a4f03..5e64e809a 100644 --- a/src/RestSharp/Serializers/SerializeAsAttribute.cs +++ b/src/RestSharp/Serializers/SerializeAsAttribute.cs @@ -76,7 +76,7 @@ public string TransformName(string input) { NameStyle.CamelCase => name.ToCamelCase(Culture), NameStyle.PascalCase => name.ToPascalCase(Culture), - NameStyle.LowerCase => name.ToLower(), + NameStyle.LowerCase => name.ToLower(Culture), _ => input }; } diff --git a/src/RestSharp/Serializers/Xml/XmlDeserializer.cs b/src/RestSharp/Serializers/Xml/XmlDeserializer.cs index bb8edeba6..8a5853638 100644 --- a/src/RestSharp/Serializers/Xml/XmlDeserializer.cs +++ b/src/RestSharp/Serializers/Xml/XmlDeserializer.cs @@ -182,7 +182,7 @@ protected virtual object Map(object x, XElement root) if (asType == typeof(bool)) { var toConvert = value.ToString() - .ToLower(); + .ToLower(Culture); prop.SetValue(x, XmlConvert.ToBoolean(toConvert), null); } @@ -366,7 +366,7 @@ object HandleListDerivative(XElement root, string propName, Type type) if (!elements.Any()) { - var lowerName = name.ToLower().AsNamespaced(Namespace); + var lowerName = name.ToLower(Culture).AsNamespaced(Namespace); elements = root.Descendants(lowerName).ToList(); } @@ -385,7 +385,7 @@ object HandleListDerivative(XElement root, string propName, Type type) if (!elements.Any()) { - var lowerName = name.ToLower().AsNamespaced(Namespace); + var lowerName = name.ToLower(Culture).AsNamespaced(Namespace); elements = root.Descendants() .Where(e => e.Name.LocalName.RemoveUnderscoresAndDashes() == lowerName) @@ -448,7 +448,7 @@ protected virtual object GetValueFromXml(XElement root, XName name, PropertyInfo protected virtual XElement GetElementByName(XElement root, XName name) { - var lowerName = name.LocalName.ToLower().AsNamespaced(name.NamespaceName); + var lowerName = name.LocalName.ToLower(Culture).AsNamespaced(name.NamespaceName); var camelName = name.LocalName.ToCamelCase(Culture).AsNamespaced(name.NamespaceName); if (root.Element(name) != null) @@ -487,7 +487,7 @@ protected virtual XAttribute GetAttributeByName(XElement root, XName name, bool : new List { name.LocalName, - name.LocalName.ToLower() + name.LocalName.ToLower(Culture) .AsNamespaced(name.NamespaceName), name.LocalName.ToCamelCase(Culture) .AsNamespaced(name.NamespaceName)