Commit bbc34a67 authored by Andy Wilkinson's avatar Andy Wilkinson

Polish "Handle possible regexes defensively in NamePatternFilter"

Closes gh-9730
parent c29d1c75
/* /*
* Copyright 2012-2016 the original author or authors. * Copyright 2012-2017 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
...@@ -46,8 +46,8 @@ abstract class NamePatternFilter<T> { ...@@ -46,8 +46,8 @@ abstract class NamePatternFilter<T> {
} }
public Map<String, Object> getResults(String name) { public Map<String, Object> getResults(String name) {
Pattern pattern = getRegexPattern(name); Pattern pattern = compilePatternIfNecessary(name);
if (pattern == null) { // this is not a regex if (pattern == null) {
Object value = getValue(this.source, name); Object value = getValue(this.source, name);
Map<String, Object> result = new HashMap<String, Object>(); Map<String, Object> result = new HashMap<String, Object>();
result.put(name, value); result.put(name, value);
...@@ -60,13 +60,13 @@ abstract class NamePatternFilter<T> { ...@@ -60,13 +60,13 @@ abstract class NamePatternFilter<T> {
} }
private Pattern getRegexPattern(String name) { private Pattern compilePatternIfNecessary(String name) {
for (String part : REGEX_PARTS) { for (String part : REGEX_PARTS) {
if (name.contains(part)) { if (name.contains(part)) {
try { try {
return Pattern.compile(name); return Pattern.compile(name);
} }
catch (PatternSyntaxException e) { catch (PatternSyntaxException ex) {
return null; return null;
} }
} }
......
/* /*
* Copyright 2012-2016 the original author or authors. * Copyright 2012-2017 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment