Skip to content

Commit

Permalink
FallbackConverter converts "on" to true if typeconverter is a Boolean…
Browse files Browse the repository at this point in the history
…Converter and destintionIsType is bool
  • Loading branch information
prabirshrestha committed Sep 23, 2012
1 parent df422ec commit a8590b9
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
Expand Up @@ -54,5 +54,15 @@ public void Should_convert_datetime()

result.ShouldEqual(now);
}

[Fact]
public void Should_convert_on_to_true_for_bool()
{
string input = "on";

var result = (bool)converter.Convert(input, typeof(bool), null);

result.ShouldBeTrue();
}
}
}
4 changes: 4 additions & 0 deletions src/Nancy/ModelBinding/DefaultConverters/FallbackConverter.cs
Expand Up @@ -42,6 +42,10 @@ public object Convert(string input, Type destinationType, BindingContext context
}
catch (FormatException)
{
if (destinationType == typeof(bool) && converter.GetType() == typeof(BooleanConverter) && input == "on")
{
return true;
}
return null;
}
}
Expand Down

0 comments on commit a8590b9

Please sign in to comment.