FasterXML / jackson-dataformat-csv

(DEPRECATED) -- moved under: https://github.com/FasterXML/jackson-dataformats-text
194 stars 76 forks source link

Invalid handling of quoted strings when deserializing #117

Closed JohnDilley closed 8 years ago

JohnDilley commented 8 years ago

It appears that strings with embedded commas or line feeds are not being deserialized correctly per RFC 4180 (https://tools.ietf.org/html/rfc4180)

Library version 2.6.3 My test code (in Scala) is:

import com.fasterxml.jackson.dataformat.csv.{CsvParser, CsvMapper}
import com.fasterxml.jackson.module.scala.DefaultScalaModule
import scala.collection.JavaConversions._

trait CvsUtility {
  def fromString(input: String): Seq[Seq[String]]
  def toString(input: Seq[Seq[String]]): String
}

object CvsUtilityImpl {
  this: CvsUtility =>

  def fromString(input: String): Seq[Seq[String]] = {
    val mapper = new CsvMapper()
    mapper.registerModule(DefaultScalaModule)
    mapper.enable(CsvParser.Feature.WRAP_AS_ARRAY)
    val it = mapper.readerFor(classOf[Seq[String]]).readValues[Seq[String]](input)
    it.toList
  }

  def toString(input: Seq[Seq[String]]): String = {
    ""
  }
}

Test one: CvsUtilityImpl.fromString("\"te,st\""

Expected: Seq("te,st") Actual: Seq(" "te", " st" "

Test two: CvsUtilityImpl.fromString("\"te\nst\""

Expected: Seq("te\nst") Actual: Seq("te", "st")

cowtowncoder commented 8 years ago

I agree in that specified test should pass, but I can not reproduce this with latest version (2.7.1). I am using plain jackson-databind, which could be related. I will see if I can reproduce this with 2.6 in the meantime.

cowtowncoder commented 8 years ago

Looks like I am unable to reproduce with 2.6[.5] as well.

JohnDilley commented 8 years ago

One difference between the unit test code I saw checked in on this issue and the code I use to repro is that WrapAsArray is enabled in my example above. I don't know if this makes a difference or not, but for completeness sake, perhaps both should be tested?

cowtowncoder commented 8 years ago

@JohnDilley Ouch. My bad there... was cut'n pasting and did not notice I did have that disabled. Thanks! Will see if that makes a difference.

cowtowncoder commented 8 years ago

Passes still, but it's a good idea to test both cases. Still not sure what causes problem you see.

JohnDilley commented 8 years ago

Interesting....It might be a version difference. I will build source locally and see if I can repro or narrow down the issue. This may take me a couple of days due to other priorities.

cowtowncoder commented 8 years ago

Closing for now since I can not reproduce: please re-open if it still occurs, ideally with a reproduction or at very least version information.