Class JsRegExpCheck

java.lang.Object
de.xima.fc.form.renderer.JsRegExpCheck
All Implemented Interfaces:
Predicate<String>

public class JsRegExpCheck extends Object implements Predicate<String>
Checks whether a string matches a JavaScript regexp. Adds protection against malicious regexps that may cause infinite loops.
Since:
7.0.0
Author:
XIMA MEDIA GmbH
  • Constructor Details

    • JsRegExpCheck

      public JsRegExpCheck(Object[] args)
      Creates a new regexp check with the given regexp and flags.
      Parameters:
      args - An array that contains the regexp (String) as the first item, and optional String flags as the second, third, etc. item. Currently only i, g, and m flags are supported by the regexp engine.
    • JsRegExpCheck

      public JsRegExpCheck(String regExp, String... flags)
      Parameters:
      regExp - Regexp to use.
      flags - Optional flags for the regexp. Currently only i, g, and m flags are supported by the regexp engine.
  • Method Details

    • test

      public boolean test(String value)
      Specified by:
      test in interface Predicate<String>
    • withTimeout

      public JsRegExpCheck withTimeout(long timeout, TimeUnit unit)
      Changes the default timeout. When the regexp check takes longer than this timeout, the check is aborted and the regexp is considered not to match the input.
      Parameters:
      timeout - Timeout for the regexp check.
      unit - Unit of the given timeout value.
      Returns:
      A new regexp check with the given timeout.