Skip to content

ArrayIndexOutOfBoundsException when parsing cookie #331

@Masterzach32

Description

@Masterzach32

Describe the bug
When parsing a cookie with no value, an ArrayIndexOutOfBoundsException is thrown for example:
SignOnDefault=; domain=.admin.virginia.edu; path=/; HttpOnly

To Reproduce

val request = Unirest.post("https://sisuva.admin.virginia.edu/psc/ihprd/UVSS/SA/s/WEBLIB_HCX_CM.H_CLASS_SEARCH.FieldFormula.IScript_ClassSearch?institution=UVA01&term=1202&date_from=01%2F01%2F1971&date_thru=12%2F31%2F2200&subject=CHEM&catalog_nbr=&time_range=0%2C23.5&days=&campus=&location=&acad_career=&acad_group=&rqmnt_designtn=&instruction_mode=&keyword=&class_nbr=&acad_org=CHEM&enrl_stat=&crse_attr=&crse_attr_value=&instructor_name=&session_code=&units=&page=1")
val response = request.asJson()
val cookies = response.cookies // error thrown here

Expected behavior
Cookie is parsed normally, and has an empty/blank String object as its value

Environmental Data:

  • Java Version: JDK 8u212
  • Version 3.4.00

Additional context
Error is occurring here when parsing cookie. Since the name/value pair of the cookie is split around = and no text follows, sub has only 1 value.

private Cookie(String[] split){
    int pos = 0;
    for(String s : split){
        if(pos == 0){
            String[] sub = s.split("=");
            name = sub[0];
            value = getDecode(sub[1]);
        } else {
            String[] sub = s.split("=");
            parseSection(sub);
        }
        pos++;     
    }
}

I can make a PR that changes it to this, which fixes the issue

private Cookie(String[] split){
    int pos = 0;
    for(String s : split){
        if(pos == 0){
            String[] sub = s.split("=");
            name = sub[0];
            if (sub.length == 2)
                value = getDecode(sub[1]);
            else // cookie that has no value
                value = "";
        } else {
            String[] sub = s.split("=");
            parseSection(sub);
        }
        pos++;     
    }
}

Has anyone else encountered this?

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugOh Noes! A bug

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions