Fixed #1579 forgiving of bad quality CSV
This commit is contained in:
parent
50500ac99d
commit
cb84946467
|
@ -59,6 +59,9 @@ public class QuotedCSV implements Iterable<String>
|
|||
*/
|
||||
public void addValue(String value)
|
||||
{
|
||||
if (value == null)
|
||||
return;
|
||||
|
||||
StringBuffer buffer = new StringBuffer();
|
||||
|
||||
int l=value.length();
|
||||
|
@ -172,6 +175,11 @@ public class QuotedCSV implements Iterable<String>
|
|||
// It wasn't really a value, it was a param name
|
||||
value_length=param_name=0;
|
||||
buffer.setLength(nws_length); // trim following OWS
|
||||
String param = buffer.toString();
|
||||
buffer.setLength(0);
|
||||
parsedValue(buffer);
|
||||
value_length=buffer.length();
|
||||
buffer.append(param);
|
||||
buffer.append(c);
|
||||
last_length=++nws_length;
|
||||
state=State.PARAM_VALUE;
|
||||
|
@ -314,4 +322,13 @@ public class QuotedCSV implements Iterable<String>
|
|||
}
|
||||
return buffer.toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString()
|
||||
{
|
||||
List<String> list = new ArrayList<>();
|
||||
for (String s : this)
|
||||
list.add(s);
|
||||
return list.toString();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -100,8 +100,6 @@ public class QuotedQualityCSV extends QuotedCSV implements Iterable<String>
|
|||
public void addValue(String value)
|
||||
{
|
||||
super.addValue(value);
|
||||
while(_quality.size()<_values.size())
|
||||
_quality.add(ONE);
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
|
@ -109,6 +107,7 @@ public class QuotedQualityCSV extends QuotedCSV implements Iterable<String>
|
|||
protected void parsedValue(StringBuffer buffer)
|
||||
{
|
||||
super.parsedValue(buffer);
|
||||
_quality.add(ONE);
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
|
@ -120,7 +119,7 @@ public class QuotedQualityCSV extends QuotedCSV implements Iterable<String>
|
|||
if (buffer.charAt(buffer.length()-1)==';')
|
||||
buffer.setLength(buffer.length()-1);
|
||||
}
|
||||
if (paramValue>=0 &&
|
||||
else if (paramValue>=0 &&
|
||||
buffer.charAt(paramName)=='q' && paramValue>paramName &&
|
||||
buffer.length()>=paramName && buffer.charAt(paramName+1)=='=')
|
||||
{
|
||||
|
@ -134,12 +133,11 @@ public class QuotedQualityCSV extends QuotedCSV implements Iterable<String>
|
|||
catch(Exception e)
|
||||
{
|
||||
q=ZERO;
|
||||
}
|
||||
buffer.setLength(paramName-1);
|
||||
}
|
||||
buffer.setLength(Math.max(0,paramName-1));
|
||||
|
||||
while(_quality.size()<_values.size())
|
||||
_quality.add(ONE);
|
||||
_quality.add(q);
|
||||
if (!ONE.equals(q))
|
||||
_quality.set(_quality.size()-1,q);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -158,6 +158,70 @@ public class QuotedQualityCSVTest
|
|||
"value1.0",
|
||||
"value0.5;p=v"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBad()
|
||||
{
|
||||
QuotedQualityCSV values = new QuotedQualityCSV();
|
||||
|
||||
|
||||
// None of these should throw exceptions
|
||||
values.addValue(null);
|
||||
values.addValue("");
|
||||
|
||||
values.addValue(";");
|
||||
values.addValue("=");
|
||||
values.addValue(",");
|
||||
|
||||
values.addValue(";;");
|
||||
values.addValue(";=");
|
||||
values.addValue(";,");
|
||||
values.addValue("=;");
|
||||
values.addValue("==");
|
||||
values.addValue("=,");
|
||||
values.addValue(",;");
|
||||
values.addValue(",=");
|
||||
values.addValue(",,");
|
||||
|
||||
values.addValue(";;;");
|
||||
values.addValue(";;=");
|
||||
values.addValue(";;,");
|
||||
values.addValue(";=;");
|
||||
values.addValue(";==");
|
||||
values.addValue(";=,");
|
||||
values.addValue(";,;");
|
||||
values.addValue(";,=");
|
||||
values.addValue(";,,");
|
||||
|
||||
values.addValue("=;;");
|
||||
values.addValue("=;=");
|
||||
values.addValue("=;,");
|
||||
values.addValue("==;");
|
||||
values.addValue("===");
|
||||
values.addValue("==,");
|
||||
values.addValue("=,;");
|
||||
values.addValue("=,=");
|
||||
values.addValue("=,,");
|
||||
|
||||
values.addValue(",;;");
|
||||
values.addValue(",;=");
|
||||
values.addValue(",;,");
|
||||
values.addValue(",=;");
|
||||
values.addValue(",==");
|
||||
values.addValue(",=,");
|
||||
values.addValue(",,;");
|
||||
values.addValue(",,=");
|
||||
values.addValue(",,,");
|
||||
|
||||
values.addValue("x;=1");
|
||||
values.addValue("=1");
|
||||
values.addValue("q=x");
|
||||
values.addValue("q=0");
|
||||
values.addValue("q=");
|
||||
values.addValue("q=,");
|
||||
values.addValue("q=;");
|
||||
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
|
||||
|
|
Loading…
Reference in New Issue