[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: 8.3.4: comma separated?! app:accept




2007/3/11, James M Snell:

Ok, so please explain this to me.

From Abdera code:

  public String[] getAccept(){
    String accept = _getElementValue(ACCEPT);
    String[] list = accept.split("\\s*,\\s*");
    return MimeTypeHelper.condense(list);
  }

The third line condenses the list to remove any duplicate or more
specific equivalent entries (e.g. "image/png, image/*" becomes simply
"image/*")

Where's the excess complexity?

In the fact the above code has a bug.

This is a *correct* app:accept:
<app:accept>application/x-my.own;parameter="something with a comma, in
it", image/*</app:accept>

With your code, it would be split into:
1. application/x-my.own;parameter="something with a comma
2. in it"
3. image/*

There are similar very frequent bugs in parsing media-types
parameters, failing to ignore semi-colons in quoted-strings (not even
accounting for quoted-pairs involving a quoted double-quote char)

For an accurate media-ranges parsing algorithm (it has not yet proven
to have bugs), look at httplib2.

--
Thomas Broyer