Skip to content

Fixed some issues when adding some additional tests #2285

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

Merged
merged 1 commit into from
Sep 5, 2023
Merged
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
37 changes: 14 additions & 23 deletions src/Microsoft.IdentityModel.JsonWebTokens/Json/JsonClaimSet.cs
Original file line number Diff line number Diff line change
Expand Up @@ -213,21 +213,23 @@ internal T GetValue<T>(string key, bool throwEx, out bool found)
// the below here should only be simple types, string, int, ...
else if (typeof(T) == typeof(string))
{
return (T)((object)obj.ToString());
if (objType == typeof(DateTime))
return (T)((object)((DateTime)obj).ToString("o", CultureInfo.InvariantCulture));

return (T)((object)obj.ToString());
}
else if (typeof(T) == typeof(bool))
{
if (bool.TryParse(obj.ToString(), out bool value))
return (T)(object)value;
}
else if (typeof(T) == typeof(int))
{
if (objType == typeof(int))
return (T)obj;

if (int.TryParse(obj.ToString(), out int value))
return (T)(object)value;
}
else if (typeof(T) == typeof(long))
{
if (objType == typeof(long))
return (T)obj;

if (objType == typeof(int))
return (T)(object)(long)(int)obj;

Expand Down Expand Up @@ -255,7 +257,6 @@ internal T GetValue<T>(string key, bool throwEx, out bool found)

return (T)(object)new Collection<string> { obj.ToString() };
}

else if (typeof(T) == typeof(object[]))
return (T)(object)new object[] { obj };

Expand All @@ -267,9 +268,6 @@ internal T GetValue<T>(string key, bool throwEx, out bool found)

else if (typeof(T) == typeof(DateTime))
{
if (objType == typeof(DateTime))
return (T)obj;

if (DateTime.TryParse(obj.ToString(), out DateTime value))
return (T)(object)value;
}
Expand All @@ -294,33 +292,26 @@ internal T GetValue<T>(string key, bool throwEx, out bool found)
}
else if (typeof(T) == typeof(double))
{
if (objType == typeof(double))
return (T)obj;

if(double.TryParse(obj.ToString(), out double value))
return (T)(object)value;
}
else if (typeof(T) == typeof(uint))
{
if (objType == typeof(uint))
return (T)obj;

if (uint.TryParse(obj.ToString(), out uint value))
return (T)(object)value;
}
else if (typeof(T) == typeof(ulong))
{
if (ulong.TryParse(obj.ToString(), out ulong value))
return (T)(object)value;
}
else if (typeof(T) == typeof(float))
{
if (objType == typeof(float))
return (T)obj;

if (float.TryParse(obj.ToString(), out float value))
return (T)(object)value;
}
else if (typeof(T) == typeof(decimal))
{
if (objType == typeof(decimal))
return (T)obj;

if (decimal.TryParse(obj.ToString(), out decimal value))
return (T)(object)value;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -825,7 +825,7 @@ public static void WriteObject(ref Utf8JsonWriter writer, string key, object obj
else if (obj is bool b)
writer.WriteBoolean(key, b);
else if (obj is DateTime dt)
writer.WriteString(key, dt.ToUniversalTime());
writer.WriteString(key, dt.ToUniversalTime().ToString("o", CultureInfo.InvariantCulture));
else if (typeof(IDictionary).IsAssignableFrom(objType))
{
IDictionary dictionary = (IDictionary)obj;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,7 @@ public GetPayloadValueTheoryData(string testId) : base(testId)
public Type PropertyType { get; set; }

public object PropertyValue { get; set; }

public string Json { get; set; }
}
}
Loading