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 class
MatcherUtil.MatchingException
-
Field Summary
Fields Modifier and Type Field Description static int
DEFAULT_REGEX_MATCHING_TIMEOUT_MS
static String
REGEX_MATCHING_TIMEOUT_MS
-
Constructor Summary
Constructors Constructor Description MatcherUtil()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static Matcher
createMatcherWithTimeout(String input, Pattern pattern, int timeout)
static String
find(String input, String regex)
static String
find(String input, String regex, int timeout)
Attempts to find a subsequence of the provided input sequence that matches the provided pattern.static String
find(String input, Pattern pattern)
Uses default timeout specified byREGEX_MATCHING_TIMEOUT_MS
internal property or default timeout specified byDEFAULT_REGEX_MATCHING_TIMEOUT_MS
or falls back to regular matching without timeout in case of negativeREGEX_MATCHING_TIMEOUT_MS
internal property valuestatic String
find(String input, Pattern pattern, int timeout)
Same as the above method, but accepts compiledPattern
static String
find(Matcher matcher)
static String
find(Matcher matcher, int start)
static boolean
matches(String input, String regex, int timeout)
Match the provided input against the provided regular expression.static boolean
matches(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_MS
internal property or default timeout specified byDEFAULT_REGEX_MATCHING_TIMEOUT_MS
or falls back to regular matching without timeout in case of negativeREGEX_MATCHING_TIMEOUT_MS
internal 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.MatchingException
Match 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.MatchingException
Match the provided input against the provided regular expression. Return false in case the matcing takes more than timeout milliseconds.- Throws:
MatcherUtil.MatchingException
-
-