You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@jena.apache.org by Ian Emmons <ie...@bbn.com> on 2011/04/06 21:56:29 UTC

Minor bug in CSV serialization of SPARQL result sets

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

Re: Minor bug in CSV serialization of SPARQL result sets

Posted by Andy Seaborne <an...@epimorphics.com>.
Fixed in SVN - thanks.

	Andy


On 06/04/11 20:56, Ian Emmons wrote:
> 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