Menu

#299 getQueryString is wrong for params without values

closed-accepted
None
5
2008-04-15
2005-05-31
No

This test case fails:

WebRequest request = new
GetMethodWebRequest("http://localhost/pathinfo?queryString");
assertEquals("queryString", request.getQueryString());

It returns "" instead of "queryString" minus quotes

Using setParameter to workaround this:

WebRequest request = new
GetMethodWebRequest("http://localhost/pathinfo?queryString");
request.setParameter("queryString","");
assertEquals("queryString", request.getQueryString());

returns "queryString=" instead of "queryString" minus
quotes. This is probably correct behavior.

However, we need a way to just return the parameter and
not the equal sign. i.e.

WebRequest request = new
GetMethodWebRequest("http://localhost/pathinfo?queryString");
request.setParameter("queryString",(String)null);
assertEquals("queryString", request.getQueryString());

But this also fails, the returned value is:
"queryString=" instead of "queryString" minus quotes.

Attached is a patch to support Null values.

This also passes with this test case:

public void testGetQueryString() throws Exception {
WebRequest wr = new
GetMethodWebRequest("http://localhost?wsdl");
wr.setParameter("abc","def");
wr.setParameter("def","");
wr.setParameter("test",(String)null);
wr.setParameter("wsdl", (String)null);

assertEquals("wsdl&abc=def&def=&test",wr.getQueryString());
}

Discussion

  • Brian Bonner

    Brian Bonner - 2005-05-31

    Patch to UncheckedParameterHolder to support null values for proper query string creation.

     
  • Wolfgang Fahl

    Wolfgang Fahl - 2008-04-09
    • assigned_to: nobody --> wolfgang_fahl
    • status: open --> open-accepted
     
  • Wolfgang Fahl

    Wolfgang Fahl - 2008-04-09

    Logged In: YES
    user_id=1220573
    Originator: NO

    Dear Brian,

    thank you for your bug report I'll look into this now together with the upcoming 1.7/2.0 releases of httpunit

    Yours
    Wolfgang

     
  • Wolfgang Fahl

    Wolfgang Fahl - 2008-04-15

    Logged In: YES
    user_id=1220573
    Originator: NO

    The change is now in the subversion repository and will be in the next build

     
  • Wolfgang Fahl

    Wolfgang Fahl - 2008-04-15
    • status: open-accepted --> closed-accepted
     
  • Wolfgang Fahl

    Wolfgang Fahl - 2008-04-15

    Logged In: YES
    user_id=1220573
    Originator: NO

    Dear Brian,

    thank you - I've added your patch as follows:
    http://httpunit.svn.sourceforge.net/viewvc/httpunit?view=rev&revision=918

    Your initial assertion still does not work - just the work-around.
    Anybody got an improvement here?

    Yours
    Wolfgang

     

Log in to post a comment.