Skip to content

Commit 5bbca8a

Browse files
authored
Merge pull request #55 from xmlunit/placeholders-tweaks
catch and tranform exception when regex pattern is invalid
2 parents 78dddf8 + 1da1a40 commit 5bbca8a

2 files changed

Lines changed: 11 additions & 4 deletions

File tree

appveyor.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ image:
77
- Visual Studio 2022
88

99
skip_tags: true
10+
skip_branch_with_pr: true
1011

1112
environment:
1213
DOTNET_ROLL_FORWARD: Major

src/main/net-placeholders/MatchesRegexPlaceholderHandler.cs

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ the License. You may obtain a copy of the License at
1111
See the License for the specific language governing permissions and
1212
limitations under the License.
1313
*/
14+
using System;
1415
using System.Text.RegularExpressions;
1516
using Org.XmlUnit.Diff;
1617

@@ -30,12 +31,17 @@ public class MatchesRegexPlaceholderHandler : IPlaceholderHandler {
3031
public string Keyword { get { return PLACEHOLDER_NAME; } }
3132
/// <inheritdoc/>
3233
public ComparisonResult Evaluate(string testText, params string[] args) {
33-
if (args.Length > 0 && args[0] != null && args[0] != "") {
34-
var pattern = new Regex(args[0].Trim());
35-
if (testText != null && Evaluate(testText.Trim(), pattern)) {
36-
return ComparisonResult.EQUAL;
34+
if (args.Length > 0 && !string.IsNullOrEmpty(args[0])) {
35+
try {
36+
var pattern = new Regex(args[0].Trim());
37+
if (testText != null && Evaluate(testText.Trim(), pattern)) {
38+
return ComparisonResult.EQUAL;
39+
}
40+
} catch(ArgumentException e) {
41+
throw new XMLUnitException(e.Message, e);
3742
}
3843
}
44+
3945
return ComparisonResult.DIFFERENT;
4046
}
4147

0 commit comments

Comments
 (0)