mirror of
https://github.com/wiremock/WireMock.Net.git
synced 2026-04-23 01:08:49 +02:00
Added try-catch for return Matchers
This commit is contained in:
@@ -1,4 +1,5 @@
|
|||||||
using JetBrains.Annotations;
|
using System;
|
||||||
|
using JetBrains.Annotations;
|
||||||
using Newtonsoft.Json.Linq;
|
using Newtonsoft.Json.Linq;
|
||||||
using WireMock.Validation;
|
using WireMock.Validation;
|
||||||
|
|
||||||
@@ -35,10 +36,17 @@ namespace WireMock.Matchers
|
|||||||
if (input == null)
|
if (input == null)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
JObject o = JObject.Parse(input);
|
try
|
||||||
JToken token = o.SelectToken(_pattern);
|
{
|
||||||
|
JObject o = JObject.Parse(input);
|
||||||
return token != null;
|
JToken token = o.SelectToken(_pattern);
|
||||||
|
|
||||||
|
return token != null;
|
||||||
|
}
|
||||||
|
catch (Exception)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,4 +1,5 @@
|
|||||||
using System.Text.RegularExpressions;
|
using System;
|
||||||
|
using System.Text.RegularExpressions;
|
||||||
using JetBrains.Annotations;
|
using JetBrains.Annotations;
|
||||||
using WireMock.Validation;
|
using WireMock.Validation;
|
||||||
|
|
||||||
@@ -32,7 +33,17 @@ namespace WireMock.Matchers
|
|||||||
/// </returns>
|
/// </returns>
|
||||||
public bool IsMatch(string input)
|
public bool IsMatch(string input)
|
||||||
{
|
{
|
||||||
return input != null && _expression.IsMatch(input);
|
if (input == null)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
return _expression.IsMatch(input);
|
||||||
|
}
|
||||||
|
catch (Exception)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,4 +1,5 @@
|
|||||||
using System.Xml;
|
using System;
|
||||||
|
using System.Xml;
|
||||||
using JetBrains.Annotations;
|
using JetBrains.Annotations;
|
||||||
using WireMock.Validation;
|
using WireMock.Validation;
|
||||||
using Wmhelp.XPath2;
|
using Wmhelp.XPath2;
|
||||||
@@ -36,10 +37,17 @@ namespace WireMock.Matchers
|
|||||||
if (input == null)
|
if (input == null)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
var nav = new XmlDocument { InnerXml = input }.CreateNavigator();
|
try
|
||||||
object result = nav.XPath2Evaluate($"boolean({_pattern})");
|
{
|
||||||
|
var nav = new XmlDocument { InnerXml = input }.CreateNavigator();
|
||||||
|
object result = nav.XPath2Evaluate($"boolean({_pattern})");
|
||||||
|
|
||||||
return true.Equals(result);
|
return true.Equals(result);
|
||||||
|
}
|
||||||
|
catch (Exception)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user