Package jetbrains.buildServer.util.regex
Class MatcherUtil
- java.lang.Object
-
- jetbrains.buildServer.util.regex.MatcherUtil
-
public final class MatcherUtil extends java.lang.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 java.lang.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 java.util.regex.Matcher
createMatcherWithTimeout(java.lang.String input, java.util.regex.Pattern pattern, int timeout)
static java.lang.String
find(java.lang.String input, java.lang.String regex)
static java.lang.String
find(java.lang.String input, java.lang.String regex, int timeout)
Attempts to find a subsequence of the provided input sequence that matches the provided pattern.static java.lang.String
find(java.lang.String input, java.util.regex.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 java.lang.String
find(java.lang.String input, java.util.regex.Pattern pattern, int timeout)
Same as the above method, but accepts compiledPattern
static java.lang.String
find(java.util.regex.Matcher matcher)
static java.lang.String
find(java.util.regex.Matcher matcher, int start)
static boolean
matches(java.lang.String input, java.lang.String regex, int timeout)
Match the provided input against the provided regular expression.static boolean
matches(java.lang.String input, java.util.regex.Pattern pattern, int timeout)
Match the provided input against the provided regular expression.
-
-
-
Field Detail
-
REGEX_MATCHING_TIMEOUT_MS
public static final java.lang.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 java.lang.String find(@NotNull java.lang.String input, @NotNull java.lang.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 java.lang.String find(@NotNull java.lang.String input, @NotNull java.util.regex.Pattern pattern, int timeout) throws MatcherUtil.MatchingException
Same as the above method, but accepts compiledPattern
- Throws:
MatcherUtil.MatchingException
-
find
@Nullable public static java.lang.String find(@NotNull java.lang.String input, @NotNull java.util.regex.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 java.lang.String find(@NotNull java.lang.String input, @NotNull java.lang.String regex) throws MatcherUtil.MatchingException
- Throws:
MatcherUtil.MatchingException
-
find
@Nullable public static java.lang.String find(@NotNull java.util.regex.Matcher matcher) throws MatcherUtil.MatchingException
- Throws:
MatcherUtil.MatchingException
-
find
@Nullable public static java.lang.String find(@NotNull java.util.regex.Matcher matcher, int start)
-
matches
public static boolean matches(@NotNull java.lang.String input, @NotNull java.lang.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 java.lang.String input, @NotNull java.util.regex.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
-
createMatcherWithTimeout
@NotNull public static java.util.regex.Matcher createMatcherWithTimeout(@NotNull java.lang.String input, @NotNull java.util.regex.Pattern pattern, int timeout)
-
-