Class XmlChars

java.lang.Object
io.jenkins.plugins.batchcontrol.store.XmlChars

@Restricted(org.kohsuke.accmod.restrictions.NoExternalUse.class) public final class XmlChars extends Object
D-72b (2), security-35 S-35-03: the characters a stored text may contain. Batch Control's files are XML 1.0, which cannot carry the control characters U+0000 to U+001F other than tab, line feed and carriage return, the non-characters U+FFFE and U+FFFF, or half of a surrogate pair. Such a character either makes the save fail (U+0000, U+FFFE, U+FFFF, a lone surrogate) or does not survive a reload (the other control characters), so a text holding one is refused before anything is stored.
  • Method Details

    • firstInvalid

      public static int firstInvalid(@CheckForNull CharSequence text)
      The index of the first character of text that XML 1.0 cannot store, or -1 when there is none (null has none).
    • isStorable

      public static boolean isStorable(@CheckForNull CharSequence text)
      Whether text holds only characters XML 1.0 can store.
    • describe

      public static String describe(CharSequence text, int index)
      The character at index of text as U+XXXX, for a refusal message.
    • requireStorable

      public static void requireStorable(@CheckForNull String text, String field)
      R1-01: refuses a user-entered text that holds a character XML 1.0 cannot store, before anything is stored. The message is the one the run request form already uses: "The <field> contains a character that cannot be stored (U+000B); remove it and submit again.". null and storable texts pass. The web layer answers the IllegalArgumentException with a refusal on the form (HTTP 400).
      Parameters:
      field - what the text is, as the message names it ("comment", "reason")
    • removeInvalid

      @CheckForNull public static String removeInvalid(@CheckForNull String text)
      R1-01: text without the characters XML 1.0 cannot store. For system text taken from outside the plugin (a console line, a build's parameter value) and kept for display only; every other character is kept as it is. null stays null.