Issue #1351 Ignore missing quality
This commit is contained in:
parent
45232639ba
commit
5d6a1e3025
|
@ -67,7 +67,14 @@ public class QuotedQualityCSV extends QuotedCSV implements Iterable<String>
|
|||
@Override
|
||||
protected void parsedParam(StringBuffer buffer, int valueLength, int paramName, int paramValue)
|
||||
{
|
||||
if (buffer.charAt(paramName)=='q' && paramValue>paramName && buffer.charAt(paramName+1)=='=')
|
||||
if (paramName<0)
|
||||
{
|
||||
if (buffer.charAt(buffer.length()-1)==';')
|
||||
buffer.setLength(buffer.length()-1);
|
||||
}
|
||||
if (paramValue>=0 &&
|
||||
buffer.charAt(paramName)=='q' && paramValue>paramName &&
|
||||
buffer.length()>=paramName && buffer.charAt(paramName+1)=='=')
|
||||
{
|
||||
Double q;
|
||||
try
|
||||
|
@ -108,7 +115,6 @@ public class QuotedQualityCSV extends QuotedCSV implements Iterable<String>
|
|||
_sorted=true;
|
||||
|
||||
Double last = ZERO;
|
||||
int len = Integer.MIN_VALUE;
|
||||
|
||||
for (int i = _values.size(); i-- > 0;)
|
||||
{
|
||||
|
@ -116,20 +122,18 @@ public class QuotedQualityCSV extends QuotedCSV implements Iterable<String>
|
|||
Double q = _quality.get(i);
|
||||
|
||||
int compare=last.compareTo(q);
|
||||
if (compare > 0 || (compare==0 && v.length()<len))
|
||||
if (compare > 0)
|
||||
{
|
||||
_values.set(i, _values.get(i + 1));
|
||||
_values.set(i + 1, v);
|
||||
_quality.set(i, _quality.get(i + 1));
|
||||
_quality.set(i + 1, q);
|
||||
last = ZERO;
|
||||
len=0;
|
||||
i = _values.size();
|
||||
continue;
|
||||
}
|
||||
|
||||
last=q;
|
||||
len=v.length();
|
||||
}
|
||||
|
||||
int last_element=_quality.size();
|
||||
|
|
|
@ -433,15 +433,41 @@ public class HttpFieldsTest
|
|||
fields.add("name", "nothing;q=0");
|
||||
fields.add("name", "one;q=0.4");
|
||||
fields.add("name", "three;x=y;q=0.2;a=b,two;q=0.3");
|
||||
fields.add("name", "first;");
|
||||
|
||||
|
||||
List<String> list = fields.getQualityCSV("name");
|
||||
assertEquals("zero",HttpFields.valueParameters(list.get(0),null));
|
||||
assertEquals("one",HttpFields.valueParameters(list.get(1),null));
|
||||
assertEquals("two",HttpFields.valueParameters(list.get(2),null));
|
||||
assertEquals("three",HttpFields.valueParameters(list.get(3),null));
|
||||
assertEquals("four",HttpFields.valueParameters(list.get(4),null));
|
||||
assertEquals("first",HttpFields.valueParameters(list.get(0),null));
|
||||
assertEquals("zero",HttpFields.valueParameters(list.get(1),null));
|
||||
assertEquals("one",HttpFields.valueParameters(list.get(2),null));
|
||||
assertEquals("two",HttpFields.valueParameters(list.get(3),null));
|
||||
assertEquals("three",HttpFields.valueParameters(list.get(4),null));
|
||||
assertEquals("four",HttpFields.valueParameters(list.get(5),null));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetQualityCSVHeader() throws Exception
|
||||
{
|
||||
HttpFields fields = new HttpFields();
|
||||
|
||||
fields.put("some", "value");
|
||||
fields.add("Accept", "zero;q=0.9,four;q=0.1");
|
||||
fields.put("other", "value");
|
||||
fields.add("Accept", "nothing;q=0");
|
||||
fields.add("Accept", "one;q=0.4");
|
||||
fields.add("Accept", "three;x=y;q=0.2;a=b,two;q=0.3");
|
||||
fields.add("Accept", "first;");
|
||||
|
||||
|
||||
List<String> list = fields.getQualityCSV(HttpHeader.ACCEPT);
|
||||
assertEquals("first",HttpFields.valueParameters(list.get(0),null));
|
||||
assertEquals("zero",HttpFields.valueParameters(list.get(1),null));
|
||||
assertEquals("one",HttpFields.valueParameters(list.get(2),null));
|
||||
assertEquals("two",HttpFields.valueParameters(list.get(3),null));
|
||||
assertEquals("three",HttpFields.valueParameters(list.get(4),null));
|
||||
assertEquals("four",HttpFields.valueParameters(list.get(5),null));
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testDateFields() throws Exception
|
||||
|
|
|
@ -47,7 +47,9 @@ public class QuotedQualityCSVTest
|
|||
{
|
||||
QuotedQualityCSV values = new QuotedQualityCSV();
|
||||
values.addValue("text/*, text/plain, text/plain;format=flowed, */*");
|
||||
Assert.assertThat(values,Matchers.contains("text/plain;format=flowed","text/plain","text/*","*/*"));
|
||||
|
||||
// Note this sort is only on quality and not the most specific type as per 5.3.2
|
||||
Assert.assertThat(values,Matchers.contains("text/*","text/plain","text/plain;format=flowed","*/*"));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -78,9 +80,9 @@ public class QuotedQualityCSVTest
|
|||
Assert.assertThat(values,Matchers.contains(
|
||||
"compress",
|
||||
"gzip",
|
||||
"gzip",
|
||||
"gzip",
|
||||
"*",
|
||||
"gzip",
|
||||
"gzip",
|
||||
"compress",
|
||||
"identity"
|
||||
));
|
||||
|
@ -144,4 +146,22 @@ public class QuotedQualityCSVTest
|
|||
"value1.0",
|
||||
"value0.5;p=v"));
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testSameQuality()
|
||||
{
|
||||
QuotedQualityCSV values = new QuotedQualityCSV();
|
||||
values.addValue("one;q=0.5,two;q=0.5,three;q=0.5");
|
||||
Assert.assertThat(values.getValues(),Matchers.contains("one","two","three"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNoQuality()
|
||||
{
|
||||
QuotedQualityCSV values = new QuotedQualityCSV();
|
||||
values.addValue("one,two;,three;x=y");
|
||||
Assert.assertThat(values.getValues(),Matchers.contains("one","two","three;x=y"));
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue