mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2026-02-09 09:16:41 +08:00
Handling wrong date format from XmlRpc clients
http://orchard.codeplex.com/workitem/16623 --HG-- branch : dev
This commit is contained in:
@@ -1,4 +1,5 @@
|
|||||||
using System;
|
using System;
|
||||||
|
using System.Threading;
|
||||||
using System.Xml.Linq;
|
using System.Xml.Linq;
|
||||||
using NUnit.Framework;
|
using NUnit.Framework;
|
||||||
using Orchard.Core.XmlRpc.Models;
|
using Orchard.Core.XmlRpc.Models;
|
||||||
@@ -87,6 +88,18 @@ namespace Orchard.Tests.Modules.XmlRpc.Services {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void StructShouldMapDefaultDateTimeWithBadFormat() {
|
||||||
|
var source = XElement.Parse(@"
|
||||||
|
<struct>
|
||||||
|
<member><name>seven</name><value><dateTime.iso8601>FOO</dateTime.iso8601></value></member>
|
||||||
|
</struct>");
|
||||||
|
|
||||||
|
var xmlStruct = _structMapper.Map(source);
|
||||||
|
Assert.That(xmlStruct["seven"], Is.GreaterThan(DateTime.Now.AddSeconds(-1)));
|
||||||
|
Assert.That(xmlStruct["seven"], Is.LessThan(DateTime.Now.AddSeconds(1)));
|
||||||
|
}
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
public void ArrayShouldBringDataItemsWithCorrectType() {
|
public void ArrayShouldBringDataItemsWithCorrectType() {
|
||||||
var source = XElement.Parse(@"
|
var source = XElement.Parse(@"
|
||||||
|
|||||||
@@ -22,7 +22,13 @@ namespace Orchard.Core.XmlRpc.Services {
|
|||||||
{"boolean", x=>new XRpcData<bool> { Value = ((string)x=="1") }},
|
{"boolean", x=>new XRpcData<bool> { Value = ((string)x=="1") }},
|
||||||
{"string", x=>new XRpcData<string> { Value = (string)x }},
|
{"string", x=>new XRpcData<string> { Value = (string)x }},
|
||||||
{"double", x=>new XRpcData<double> { Value = (double)x }},
|
{"double", x=>new XRpcData<double> { Value = (double)x }},
|
||||||
{"dateTime.iso8601", x=>new XRpcData<DateTime> { Value = DateTime.Parse((string)x, null, DateTimeStyles.RoundtripKind) }},
|
{"dateTime.iso8601", x=> {
|
||||||
|
DateTime parsedDateTime;
|
||||||
|
if(!DateTime.TryParse(x.Value, out parsedDateTime)) {
|
||||||
|
parsedDateTime = DateTime.Now;
|
||||||
|
}
|
||||||
|
return new XRpcData<DateTime> {Value = parsedDateTime};
|
||||||
|
}},
|
||||||
{"base64", x=>new XRpcData<byte[]> { Value = Convert.FromBase64String((string)x) }},
|
{"base64", x=>new XRpcData<byte[]> { Value = Convert.FromBase64String((string)x) }},
|
||||||
{"struct", x=>XRpcData.For(Map<XRpcStruct>(x))} ,
|
{"struct", x=>XRpcData.For(Map<XRpcStruct>(x))} ,
|
||||||
{"array", x=>XRpcData.For(Map<XRpcArray>(x))} ,
|
{"array", x=>XRpcData.For(Map<XRpcArray>(x))} ,
|
||||||
@@ -46,7 +52,7 @@ namespace Orchard.Core.XmlRpc.Services {
|
|||||||
XRpcMethodCall IMapper<XElement, XRpcMethodCall>.Map(XElement source) {
|
XRpcMethodCall IMapper<XElement, XRpcMethodCall>.Map(XElement source) {
|
||||||
return new XRpcMethodCall {
|
return new XRpcMethodCall {
|
||||||
MethodName = (string)source.Element("methodName"),
|
MethodName = (string)source.Element("methodName"),
|
||||||
Params = source.Elements("params").Elements("param").Select(x => Map<XRpcData>(x)).ToList()
|
Params = source.Elements("params").Elements("param").Select(Map<XRpcData>).ToList()
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user