Skip to content

Commit

Permalink
null status fix for PublishFileMessage (#159)
Browse files Browse the repository at this point in the history
* null PublishFileMessage PNStatus handling in SendFileOperation

* refactored string formatting by adding CultureInfo.InvariantCulture

* Remove request header content-type for ObjectsV2
  • Loading branch information
budgetpreneur authored Dec 5, 2022
1 parent 207530f commit a4df5d4
Show file tree
Hide file tree
Showing 45 changed files with 526 additions and 481 deletions.
23 changes: 16 additions & 7 deletions .pubnub.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,17 @@
name: c-sharp
version: "6.12.0"
version: "6.13.0"
schema: 1
scm: github.com/pubnub/c-sharp
changelog:
- date: 2022-12-05
version: v6.13.0
changes:
- type: bug
text: "Added null check for PublishFileMessage PNStatus in SendFileOperation."
- type: bug
text: "Removed invalid Content-Type in ObjectsV2 request headers targeting .Net Frameworks."
- type: improvement
text: "Added CultureInfo.InvariantCulture to string formatting."
- date: 2022-11-14
version: v6.12.0
changes:
Expand Down Expand Up @@ -692,7 +701,7 @@ features:
- QUERY-PARAM
supported-platforms:
-
version: Pubnub 'C#' 6.12.0
version: Pubnub 'C#' 6.13.0
platforms:
- Windows 10 and up
- Windows Server 2008 and up
Expand All @@ -702,7 +711,7 @@ supported-platforms:
- .Net Framework 4.5
- .Net Framework 4.6.1+
-
version: PubnubPCL 'C#' 6.12.0
version: PubnubPCL 'C#' 6.13.0
platforms:
- Xamarin.Android
- Xamarin.iOS
Expand All @@ -722,7 +731,7 @@ supported-platforms:
- .Net Core
- .Net 6.0
-
version: PubnubUWP 'C#' 6.12.0
version: PubnubUWP 'C#' 6.13.0
platforms:
- Windows Phone 10
- Universal Windows Apps
Expand All @@ -746,7 +755,7 @@ sdks:
distribution-type: source
distribution-repository: GitHub
package-name: Pubnub
location: https://github.com/pubnub/c-sharp/releases/tag/v6.12.0.0
location: https://github.com/pubnub/c-sharp/releases/tag/v6.13.0.0
requires:
-
name: ".Net"
Expand Down Expand Up @@ -1029,7 +1038,7 @@ sdks:
distribution-type: source
distribution-repository: GitHub
package-name: PubNubPCL
location: https://github.com/pubnub/c-sharp/releases/tag/v6.12.0.0
location: https://github.com/pubnub/c-sharp/releases/tag/v6.13.0.0
requires:
-
name: ".Net Core"
Expand Down Expand Up @@ -1388,7 +1397,7 @@ sdks:
distribution-type: source
distribution-repository: GitHub
package-name: PubnubUWP
location: https://github.com/pubnub/c-sharp/releases/tag/v6.12.0.0
location: https://github.com/pubnub/c-sharp/releases/tag/v6.13.0.0
requires:
-
name: "Universal Windows Platform Development"
Expand Down
7 changes: 7 additions & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
v6.13.0 - December 05 2022
-----------------------------
- Fixed: added null check for PublishFileMessage PNStatus in SendFileOperation.
- Fixed: removed invalid Content-Type in ObjectsV2 request headers targeting .Net Frameworks.

- Modified: added CultureInfo.InvariantCulture to string formatting.

v6.12.0 - November 14 2022
-----------------------------
- Fixed: encode comma char for push related multi channels.
Expand Down
2 changes: 1 addition & 1 deletion src/Api/PubnubApi/Builder/StatusBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public PNStatus CreateStatusResponse<T>(PNOperationType type, PNStatusCategory c
{
Dictionary<string, object> deserializeStatus = jsonLibrary.DeserializeToDictionaryOfObject(targetException.Message);
if (deserializeStatus != null && deserializeStatus.Count >= 1
&& deserializeStatus.ContainsKey("error") && string.Equals(deserializeStatus["error"].ToString(), "true", StringComparison.CurrentCultureIgnoreCase)
&& deserializeStatus.ContainsKey("error") && string.Equals(deserializeStatus["error"].ToString(), "true", StringComparison.OrdinalIgnoreCase)
&& deserializeStatus.ContainsKey("status") && Int32.TryParse(deserializeStatus["status"].ToString(), out serverErrorStatusCode))
{
serverErrorMessage = true;
Expand Down
46 changes: 23 additions & 23 deletions src/Api/PubnubApi/Builder/UriUtil.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,41 +33,41 @@ public static string EncodeUriComponent(string s, PNOperationType type, bool ign
int positionOfChar = index;
if ((ch == ',' && ignoreComma) || (ch == ':' && ignoreColon))
{
o.Append(ch.ToString());
o.Append(ch);
}
else if (Char.IsSurrogatePair(s, positionOfChar))
{
string codepoint = ConvertToUtf32(s, positionOfChar).ToString("X4");
string codepoint = ConvertToUtf32(s, positionOfChar).ToString("X4", CultureInfo.InvariantCulture);

int codePointValue = int.Parse(codepoint, NumberStyles.HexNumber);
int codePointValue = int.Parse(codepoint, NumberStyles.HexNumber, CultureInfo.InvariantCulture);
if (codePointValue <= 0x7F)
{
System.Diagnostics.Debug.WriteLine("0x7F");
string utf8HexValue = string.Format("%{0}", codePointValue);
string utf8HexValue = string.Format(CultureInfo.InvariantCulture, "%{0}", codePointValue);
o.Append(utf8HexValue);
}
else if (codePointValue <= 0x7FF)
{
string one = (0xC0 | ((codePointValue >> 6) & 0x1F)).ToString("X");
string two = (0x80 | (codePointValue & 0x3F)).ToString("X");
string utf8HexValue = string.Format("%{0}%{1}", one, two);
string one = (0xC0 | ((codePointValue >> 6) & 0x1F)).ToString("X", CultureInfo.InvariantCulture);
string two = (0x80 | (codePointValue & 0x3F)).ToString("X", CultureInfo.InvariantCulture);
string utf8HexValue = string.Format(CultureInfo.InvariantCulture, "%{0}%{1}", one, two);
o.Append(utf8HexValue);
}
else if (codePointValue <= 0xFFFF)
{
string one = (0xE0 | ((codePointValue >> 12) & 0x0F)).ToString("X");
string two = (0x80 | ((codePointValue >> 6) & 0x3F)).ToString("X");
string three = (0x80 | (codePointValue & 0x3F)).ToString("X");
string utf8HexValue = string.Format("%{0}%{1}%{2}", one, two, three);
string one = (0xE0 | ((codePointValue >> 12) & 0x0F)).ToString("X", CultureInfo.InvariantCulture);
string two = (0x80 | ((codePointValue >> 6) & 0x3F)).ToString("X", CultureInfo.InvariantCulture);
string three = (0x80 | (codePointValue & 0x3F)).ToString("X", CultureInfo.InvariantCulture);
string utf8HexValue = string.Format(CultureInfo.InvariantCulture, "%{0}%{1}%{2}", one, two, three);
o.Append(utf8HexValue);
}
else if (codePointValue <= 0x10FFFF)
{
string one = (0xF0 | ((codePointValue >> 18) & 0x07)).ToString("X");
string two = (0x80 | ((codePointValue >> 12) & 0x3F)).ToString("X");
string three = (0x80 | ((codePointValue >> 6) & 0x3F)).ToString("X");
string four = (0x80 | (codePointValue & 0x3F)).ToString("X");
string utf8HexValue = string.Format("%{0}%{1}%{2}%{3}", one, two, three, four);
string one = (0xF0 | ((codePointValue >> 18) & 0x07)).ToString("X", CultureInfo.InvariantCulture);
string two = (0x80 | ((codePointValue >> 12) & 0x3F)).ToString("X", CultureInfo.InvariantCulture);
string three = (0x80 | ((codePointValue >> 6) & 0x3F)).ToString("X", CultureInfo.InvariantCulture);
string four = (0x80 | (codePointValue & 0x3F)).ToString("X", CultureInfo.InvariantCulture);
string utf8HexValue = string.Format(CultureInfo.InvariantCulture, "%{0}%{1}%{2}%{3}", one, two, three, four);
o.Append(utf8HexValue);
}

Expand All @@ -79,7 +79,7 @@ public static string EncodeUriComponent(string s, PNOperationType type, bool ign
#if NET35 || NET40
if (escapeChar == ch.ToString() && IsUnsafeToEncode(ch, ignoreComma, ignoreColon))
{
escapeChar = string.Format("%{0}{1}", ToHex(ch / 16), ToHex(ch % 16));
escapeChar = string.Format(CultureInfo.InvariantCulture, "%{0}{1}", ToHex(ch / 16), ToHex(ch % 16));
}
#endif
o.Append(escapeChar);
Expand Down Expand Up @@ -147,16 +147,16 @@ private static char ToHex(int ch)
internal const int LowSurrogateStart = 0x00dc00;
internal const int UnicodePlane01Start = 0x10000;

private static int ConvertToUtf32(String s, int index)
private static int ConvertToUtf32(string s, int index)
{
if (s == null)
{
throw new ArgumentNullException("s");
throw new ArgumentNullException(nameof(s), "invalid.");
}

if (index < 0 || index >= s.Length)
{
throw new ArgumentOutOfRangeException("index");
throw new ArgumentOutOfRangeException(nameof(index), "invalid.");
}

// Check if the character at index is a high surrogate.
Expand All @@ -177,19 +177,19 @@ private static int ConvertToUtf32(String s, int index)
}
else
{
throw new ArgumentException("index");
throw new ArgumentException("index value invalid.");
}
}
else
{
// Found a high surrogate at the end of the string.
throw new ArgumentException("index");
throw new ArgumentException("index value invalid.");
}
}
else
{
// Find a low surrogate at the character pointed by index.
throw new ArgumentException("index");
throw new ArgumentException("index value invalid.");
}
}

Expand Down
Loading

0 comments on commit a4df5d4

Please sign in to comment.