Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8043147

java.net.HttpCookie.parse(String) will parse first value only

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Not an Issue
    • Icon: P4 P4
    • None
    • 7u17, 9
    • core-libs

      FULL PRODUCT VERSION :
      java version "1.7.0_17"
      Java(TM) SE Runtime Environment (build 1.7.0_17-b02)
      Java HotSpot(TM) Client VM (build 23.7-b01, mixed mode, sharing)

      ADDITIONAL OS VERSION INFORMATION :
      Microsoft Windows [Version 6.1.7601]

      A DESCRIPTION OF THE PROBLEM :
      During websocket handshake you can provide data using the cookie header:

        Cookie:auth=secretStuff; session=myFrontendSession.

      When you try to parse this Cookie value using java.net.HttpCookie.parse(String), the HttpCookie will try to guess the version of the Cookie.

      This value will always return 0.
      When the version is 0, HttpCookie will only parse the first value

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      create a string, like the websocket cookie header would ;
      "donald=duck; mickey=mouse"

      Try to parse this value using HttpCookie.parse(String);

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      An List<HttpCookie> that contains one HttpCookie for each value of the cookie header. [donald=duck] [mickey=mouse]
      ACTUAL -
      An List<HttpCookie> holding only one cookie for the first value of the cookie header (donald= duck).

      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
       List<HttpCookie> parse = HttpCookie.parse("donald=duck; mickey=mouse");
      ---------- END SOURCE ----------

      CUSTOMER SUBMITTED WORKAROUND :
      1) Add "version=x" to the string you want to parse
      2) Implement your own function for parsing Cookies.

            vtewari Vyom Tewari
            webbuggrp Webbug Group
            Votes:
            0 Vote for this issue
            Watchers:
            5 Start watching this issue

              Created:
              Updated:
              Resolved: