Created
September 10, 2018 05:49
-
-
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
\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} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Outputs (along with some errors)