Skip to content
This repository was archived by the owner on May 1, 2024. It is now read-only.

Commit daedd93

Browse files
committed
Fix InvalidCastException in WebEx.JsonDecode
Mono's JsonValue implementation does do conversions for their implicit casts to string, unlike the operators for numbers. Fixes #39
1 parent a4d2922 commit daedd93

File tree

4 files changed

+30
-1
lines changed

4 files changed

+30
-1
lines changed

src/Xamarin.Auth/AssemblyInfo.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,3 +40,4 @@
4040
//[assembly: AssemblyDelaySign(false)]
4141
//[assembly: AssemblyKeyFile("")]
4242

43+
[assembly: InternalsVisibleTo ("XamarinAuthiOSTest")]

src/Xamarin.Auth/WebEx.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,10 @@ public static Dictionary<string, string> JsonDecode (string encodedString)
9898
foreach (var kv in json) {
9999
var v = kv.Value as JsonValue;
100100
if (v != null) {
101-
inputs [kv.Key] = (string)v;
101+
if (v.JsonType != JsonType.String)
102+
inputs[kv.Key] = v.ToString();
103+
else
104+
inputs[kv.Key] = (string)v;
102105
}
103106
}
104107

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text;
5+
using NUnit.Framework;
6+
using Xamarin.Utilities;
7+
8+
namespace Xamarin.Auth.Test
9+
{
10+
[TestFixture]
11+
public class WebExTests
12+
{
13+
[TestCase ("{\"string\": \"value\"}","string", "value")]
14+
[TestCase ("{\"int\": 5000}", "int", "5000")]
15+
[TestCase ("{\"bool\": true }", "bool", "true")]
16+
public void JsonDecode (string json, string arg, string value)
17+
{
18+
var dict = WebEx.JsonDecode (json);
19+
string v;
20+
Assert.That (dict.TryGetValue (arg, out v), Is.True, "Dictionary did not contain argument '" + arg + "'");
21+
Assert.That (v, Is.EqualTo (value));
22+
}
23+
}
24+
}

tests/Xamarin.Auth.iOS.Test/Xamarin.Auth.iOS.Test.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@
9292
<Compile Include="OAuth1Test.cs" />
9393
<Compile Include="AccountTest.cs" />
9494
<Compile Include="RequestTest.cs" />
95+
<Compile Include="WebExTests.cs" />
9596
<Compile Include="WebUtilitiesTest.cs" />
9697
</ItemGroup>
9798
<Import Project="$(MSBuildExtensionsPath)\Xamarin\iOS\Xamarin.MonoTouch.CSharp.targets" />

0 commit comments

Comments
 (0)