Cannot write and read back arbitrary data using arbitrary CSVFormat
jedesah opened this issue · 0 comments
Example of an offending scenario:
Given the following csv format:
val format = new DefaultCSVFormat {
override val quoteChar: Char = 'd'
override val delimiter: Char = 'u'
override val escapeChar: Char = 'e'
}
I'll write this in pseudocode to keep things simple:
csv.write(format, List("foo", "true")) === "fooudtrued"
csv.read(format, "fooudtrued") === -\/("Malformed input")
// This works
csv.read(format, "fooudtrueed") === \/-(List("foo", "true"))
I am not sure whether the writer is at fault for not escaping the escape character or if it's the parser which should not interpret the escape character as such inside of a quote.
This might seem like a little bit of an academic exercise given the unlikely csv format, but it's causing test failures for us since we have scalacheck properties that generate arbitrary CSVFormat
.
I can submit a pull request with a scalacheck property that makes sure that for any Arbitrary[List[List[String]]]
and Arbitrary[CSVFormat]
, data == read(write(data))
is true, but as mentioned in my example above, I'm not sure whether the fix should be in the Parser
or the Writer
.