Class RepeatedField

java.lang.Object
io.jenkins.plugins.batchcontrol.ui.RepeatedField

@Restricted(org.kohsuke.accmod.restrictions.NoExternalUse.class) public final class RepeatedField extends Object
Reads the values of a repeated form field (one value per entry, in submission order) from an application/x-www-form-urlencoded or a multipart/form-data body alike.

Stapler keeps one value per name for a multipart body: RequestImpl parses the parts into a map keyed by field name, so a repeated field keeps only its last part. Neither getParameterValues nor getFileItem2 can return the others, and the body stream has already been consumed by then (core may have parsed it during dispatch, before any plugin code). So for a multipart request the json blob is read as well. f:form posts that blob with every submission, and Stapler parses it from the same body.

The rule (D-37):

  • multipart, and the blob holds string values for the field: those values, in their order, and nothing else. The raw part is not added: it is one of the blob's values for the rendered form, and Stapler decodes a part without a charset as ISO-8859-1, so a non-ASCII value would come back garbled (UTF-8 山田 read as å±±ç°) next to the blob's intact copy.
  • multipart without a blob, or a blob without string values for the field (for example the boolean array of checkboxes without json): the raw part, read as UTF-8 where asTyped(org.kohsuke.stapler.StaplerRequest2, java.lang.String) allows it (R4-03), else as Stapler decoded it.
  • urlencoded: getParameterValues and nothing else, as before.

R4-03: a single plain text field (text(org.kohsuke.stapler.StaplerRequest2, java.lang.String)) follows the same rule: the blob's string value when the multipart body carries one, else the part read as UTF-8 where allowed.

Nothing here parses a body that the caller has not let be parsed already. The blob is read only when the request is multipart and carries a non-empty json field, and only after getParameter, which parses the body in the first place. Callers read fields only after their permission (and, for the run request, D-72 size) checks. A blob that is not a JSON object is ignored, so the raw part is used as before. These are values only: the caller validates them.

  • Method Summary

    Modifier and Type
    Method
    Description
    static boolean
    isMultipart(org.kohsuke.stapler.StaplerRequest2 req)
    Whether Stapler reads this request's fields from a parsed multipart body (its own test).
    static String[]
    parameterValues(org.kohsuke.stapler.StaplerRequest2 req, String field)
    R4-03: getParameterValues(field) with the value of the multipart part read as UTF-8 where asTyped(org.kohsuke.stapler.StaplerRequest2, java.lang.String) allows it.
    static String
    text(org.kohsuke.stapler.StaplerRequest2 req, String field)
    R4-03: the value of the plain text field field as the user typed it, or null when the request has no such field.
    static List<String>
    values(org.kohsuke.stapler.StaplerRequest2 req, net.sf.json.JSONObject formData, String field)
     

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Method Details

    • isMultipart

      public static boolean isMultipart(org.kohsuke.stapler.StaplerRequest2 req)
      Whether Stapler reads this request's fields from a parsed multipart body (its own test).
    • values

      public static List<String> values(org.kohsuke.stapler.StaplerRequest2 req, @CheckForNull net.sf.json.JSONObject formData, String field)
      Parameters:
      req - the current request
      formData - the parsed json blob when the caller already has it, otherwise null (for a multipart request it is then read from the request)
      field - the field name, also the key of the value in the blob's top-level object
      Returns:
      the submitted values in submission order, possibly empty, never null
    • text

      @CheckForNull public static String text(org.kohsuke.stapler.StaplerRequest2 req, String field)
      R4-03: the value of the plain text field field as the user typed it, or null when the request has no such field. On a multipart body the json blob's string value for the field wins when there is one (as in values(org.kohsuke.stapler.StaplerRequest2, net.sf.json.JSONObject, java.lang.String)), else Stapler's value of the part as asTyped(org.kohsuke.stapler.StaplerRequest2, java.lang.String) reads it; on any other body getParameter, unchanged.
    • parameterValues

      @CheckForNull public static String[] parameterValues(org.kohsuke.stapler.StaplerRequest2 req, String field)
      R4-03: getParameterValues(field) with the value of the multipart part read as UTF-8 where asTyped(org.kohsuke.stapler.StaplerRequest2, java.lang.String) allows it. For a multipart body Stapler answers the query string's values followed by the part's value, so the last element is the part's; any other body is answered unchanged.