Skip to content

Instantly share code, notes, and snippets.

@oxinabox
Created September 10, 2018 05:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save oxinabox/d8074781c78ed308e1948df42a7c83d1 to your computer and use it in GitHub Desktop.
Save oxinabox/d8074781c78ed308e1948df42a7c83d1 to your computer and use it in GitHub Desktop.
Demo of how the CSV parser of PGFPlots fails to handle quotes correctly
\documentclass{article}
\usepackage{url}
\usepackage{pgfplotstable}
\pgfplotsset{compat=1.15}
\usepackage{filecontents}
\begin{filecontents}{actors.csv}
age, Name, Country
37,"Natalie Portman","Israel/USA"
46,"Dwayne ""The Rock"" Johnson", USA
1,"Line
breakerson", Linebreakville
\end{filecontents}
\begin{document}
\section{Correct output}
\begin{tabular}{c c c}
age & Name & Country\\
37 & Natalie Portman & Israel/USA"\\
46 & Dwayne ``The Rock'' Johnson & USA\\
1 & \shortstack{Line\\breakerson} & Linebreakville\\
\end{tabular}
\section{Incorrect output:}
\pgfplotstableread[col sep=comma, header=has colnames]{actors.csv}\actors
\pgfplotstabletypeset[%
columns/Name/.style={string type},
columns/Country/.style={string type},
%
]{\actors}
\section{Explain}
CF the informal-spec: \url{https://github.com/parsecsv/csv-spec/blob/master/csv-spec.md}
and RFC 4180, \url{https://tools.ietf.org/html/rfc4180}
\begin{itemize}
\item
The 1st line tests that fields can be quoted, allowed by informal-spec rule 10, RFC4180 rule 5. The quote marks themselve should not be shown.
\item
The 2nd line tests that escaping quotes within quotes should be allowed by informal-spec rule 8, RFC4180 rule 7. The inner set of quotes should be shown only once
\item
3rd line tests that newlines inside quote are handles correctly, allows by informal-spec Rule 7, RFC4180 rule 6. Which should result in the content having a line break in that cell.
\end{itemize}
\end{document}
@oxinabox
Copy link
Author

Outputs (along with some errors)

document that was output

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment