Consider the following MWE, extracted from my solution to this question:
\begin{filecontents*}{demolist1.dat}
1,2,3
\end{filecontents*}
\begin{filecontents*}{demolist2.dat}
{1,0,2},{0,3},{1,1}
\end{filecontents*}
\documentclass{article}
\usepackage{catchfile}
\usepackage{pgffor}
\CatchFileDef{\mylist}{demolist1.dat}{}
\CatchFileDef{\mynestedlist}{demolist2.dat}{}
\begin{document}
\foreach \x in \mylist {
``\x'' \quad
}
\hrulefill
\foreach \x in \mynestedlist {
\foreach \y in \x {
``\y'' \quad
}
\par
}
\end{document}
it produces

Note the extra space in the last element of the first list and the collapse of the last element of the second list.
I cannot understand why the last element of each list is treated differently.
Any idea on how to fix this?
