Package jetbrains.buildServer.util.regex
Class MatcherUtil
- java.lang.Object
-
- jetbrains.buildServer.util.regex.MatcherUtil
-
public final class MatcherUtil extends Object
Utility helping to avoid ReDoS, StackOverflowError, etc during regex matching. Potentially harmful regular expressions are the ones with repeated groups which have either repetition or alternation with overlapping inside
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classMatcherUtil.MatchingException
-
Field Summary
Fields Modifier and Type Field Description static intDEFAULT_REGEX_MATCHING_TIMEOUT_MSstatic StringREGEX_MATCHING_TIMEOUT_MS
-
Constructor Summary
Constructors Constructor Description MatcherUtil()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static MatchercreateMatcherWithTimeout(String input, Pattern pattern, int timeout)static Stringfind(String input, String regex)static Stringfind(String input, String regex, int timeout)Attempts to find a subsequence of the provided input sequence that matches the provided pattern.static Stringfind(String input, Pattern pattern)Uses default timeout specified byREGEX_MATCHING_TIMEOUT_MSinternal property or default timeout specified byDEFAULT_REGEX_MATCHING_TIMEOUT_MSor falls back to regular matching without timeout in case of negativeREGEX_MATCHING_TIMEOUT_MSinternal property valuestatic Stringfind(String input, Pattern pattern, int timeout)Same as the above method, but accepts compiledPatternstatic Stringfind(Matcher matcher)static Stringfind(Matcher matcher, int start)static booleanmatches(String input, String regex, int timeout)Match the provided input against the provided regular expression.static booleanmatches(String input, Pattern pattern, int timeout)Match the provided input against the provided regular expression.
-
-
-
Field Detail
-
REGEX_MATCHING_TIMEOUT_MS
public static final String REGEX_MATCHING_TIMEOUT_MS
- See Also:
- Constant Field Values
-
DEFAULT_REGEX_MATCHING_TIMEOUT_MS
public static final int DEFAULT_REGEX_MATCHING_TIMEOUT_MS
- See Also:
- Constant Field Values
-
-
Method Detail
-
find
@Nullable public static String find(@NotNull String input, @NotNull String regex, int timeout) throws MatcherUtil.MatchingException
Attempts to find a subsequence of the provided input sequence that matches the provided pattern. Throw exception in case the matching takes more than timeout milliseconds.- Parameters:
input- search for match inregex- searched patterntimeout- milliseconds- Returns:
- see above
- Throws:
MatcherUtil.MatchingException- see above
-
find
@Nullable public static String find(@NotNull String input, @NotNull Pattern pattern, int timeout) throws MatcherUtil.MatchingException
Same as the above method, but accepts compiledPattern- Throws:
MatcherUtil.MatchingException
-
find
@Nullable public static String find(@NotNull String input, @NotNull Pattern pattern) throws MatcherUtil.MatchingException
Uses default timeout specified byREGEX_MATCHING_TIMEOUT_MSinternal property or default timeout specified byDEFAULT_REGEX_MATCHING_TIMEOUT_MSor falls back to regular matching without timeout in case of negativeREGEX_MATCHING_TIMEOUT_MSinternal property value- Throws:
MatcherUtil.MatchingException
-
find
@Nullable public static String find(@NotNull String input, @NotNull String regex) throws MatcherUtil.MatchingException
- Throws:
MatcherUtil.MatchingException
-
find
@Nullable public static String find(@NotNull Matcher matcher) throws MatcherUtil.MatchingException
- Throws:
MatcherUtil.MatchingException
-
matches
public static boolean matches(@NotNull String input, @NotNull String regex, int timeout) throws MatcherUtil.MatchingExceptionMatch the provided input against the provided regular expression. Throw exception in case the matcing takes more than timeout milliseconds.- Throws:
MatcherUtil.MatchingException
-
matches
public static boolean matches(@NotNull String input, @NotNull Pattern pattern, int timeout) throws MatcherUtil.MatchingExceptionMatch the provided input against the provided regular expression. Return false in case the matcing takes more than timeout milliseconds.- Throws:
MatcherUtil.MatchingException
-
-