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

Commit

Permalink
Fix InvalidCastException in WebEx.JsonDecode
Browse files Browse the repository at this point in the history
Mono's JsonValue implementation does do conversions for their implicit
casts to string, unlike the operators for numbers.

Fixes #39
  • Loading branch information
ermau committed Aug 13, 2013
1 parent a4d2922 commit daedd93
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 1 deletion.
1 change: 1 addition & 0 deletions src/Xamarin.Auth/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,3 +40,4 @@
//[assembly: AssemblyDelaySign(false)]
//[assembly: AssemblyKeyFile("")]

[assembly: InternalsVisibleTo ("XamarinAuthiOSTest")]
5 changes: 4 additions & 1 deletion src/Xamarin.Auth/WebEx.cs
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,10 @@ public static Dictionary<string, string> JsonDecode (string encodedString)
foreach (var kv in json) {
var v = kv.Value as JsonValue;
if (v != null) {
inputs [kv.Key] = (string)v;
if (v.JsonType != JsonType.String)
inputs[kv.Key] = v.ToString();
else
inputs[kv.Key] = (string)v;
}
}

Expand Down
24 changes: 24 additions & 0 deletions tests/Xamarin.Auth.iOS.Test/WebExTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using NUnit.Framework;
using Xamarin.Utilities;

namespace Xamarin.Auth.Test
{
[TestFixture]
public class WebExTests
{
[TestCase ("{\"string\": \"value\"}","string", "value")]
[TestCase ("{\"int\": 5000}", "int", "5000")]
[TestCase ("{\"bool\": true }", "bool", "true")]
public void JsonDecode (string json, string arg, string value)
{
var dict = WebEx.JsonDecode (json);
string v;
Assert.That (dict.TryGetValue (arg, out v), Is.True, "Dictionary did not contain argument '" + arg + "'");
Assert.That (v, Is.EqualTo (value));
}
}
}
1 change: 1 addition & 0 deletions tests/Xamarin.Auth.iOS.Test/Xamarin.Auth.iOS.Test.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@
<Compile Include="OAuth1Test.cs" />
<Compile Include="AccountTest.cs" />
<Compile Include="RequestTest.cs" />
<Compile Include="WebExTests.cs" />
<Compile Include="WebUtilitiesTest.cs" />
</ItemGroup>
<Import Project="$(MSBuildExtensionsPath)\Xamarin\iOS\Xamarin.MonoTouch.CSharp.targets" />
Expand Down

0 comments on commit daedd93

Please sign in to comment.