In the class com.hp.hpl.jena.sparql.resultset.CSVOutput, the following method 
appears:

   private String csvSafe(String str)
   {
      str = str.replaceAll("\"", "\"\"") ; 

      if ( str.contains(",") )
         str = "\""+str+"\"" ; 
      return str ;
   }

In order to support the full breadth of the CSV file format, this method should 
be as follows:

   private String csvSafe(String str)
   {
      if (str.contains("\"")
            || str.contains(",")
            || str.contains("\r")
            || str.contains("\n"))
         str = "\"" + str.replaceAll("\"", "\"\"") + "\"";
      return str;
   }

This allows for fields that contain carriage returns and newlines, and it also 
quotes columns that contain quotes, which is expected by some parsers.

Thanks,

Ian Emmons
BBN Technologies

Reply via email to