[dev-context] Quoting problems in grph-con.lua

Kevin Boulain kevinboulain at gmail.com
Sun Apr 21 13:04:32 CEST 2019


> I'm a bit reluctant to change this as it can break existing workflows.

I understand the motivation but I don't understand the technical
reason. This seems to be a simple shell quoting problem to me.
I'm an inexperienced ConTeXt/TeX user though, so feel free to tell me
I'm utterly wrong :)

> What if you use "%[oldname]%" and don't feed an quoted argument?

I'm not sure I understood: I'm not feeding a quoted argument,
grph-con.lua introduces superfluous quotes, breaking the proper
quoting introduced later by util-sbx.lua (since the shell is used to
spawn the process).
Let me try to explain it a little bit better.

Here is a minimal reproduction (needs Inkscape installed):
dir="/tmp/s p a c e s"
mkdir -p "$dir"
cat > "$dir/test.svg"  << EOF
<?xml version="1.0" standalone="no"?>
<svg width="100" height="100" version="1.1" xmlns="http://www.w3.org/2000/svg">
  <rect x="10" y="10" width="80" height="80"/>
</svg>
EOF
cat > "$dir/test.tex" << EOF
\defineexternalfigure[test][height=1cm]
\starttext
  \externalfigure[test.svg][test]
\stoptext
EOF
(cd "$dir" && context test.tex)

1/ With an unpatched ConTeXt, the Inkscape command line is:
inkscape ""/private/tmp/s p a c e s/test.svg"" --export-dpi=600
--export-pdf=""/private/tmp/s p a c e s/m_k_i_v_test.svg.pdf""

So Inkscape can't find the file because the shell actually gives
multiple parameters (some parts omitted for brevity):
** (inkscape-bin:8703): WARNING **: Can't open file: /private/tmp/s
(doesn't exist)
** (inkscape-bin:8703): WARNING **: Specified document /private/tmp/s
cannot be opened (does not exist or not a valid SVG file)
** (inkscape-bin:8703): WARNING **: Can't open file: p (doesn't exist)
** (inkscape-bin:8703): WARNING **: Specified document p cannot be
opened (does not exist or not a valid SVG file)
** (inkscape-bin:8703): WARNING **: Can't open file: a (doesn't exist)
[...]

2/ With the proposed "%[oldname]%" patch:
         template = longtostring [[
-            "%oldname%"
+            "%[oldname]%"
             --export-dpi=%resolution%
-            --export-%format%="%newname%"
+            --export-%format%="%[newname]%"
         ]],

The Inkscape command line is:
inkscape "\"/private/tmp/s p a c e s/test.svg\"" --export-dpi=600
--export-pdf="\"/private/tmp/s p a c e s/m_k_i_v_test.svg.pdf\""

Now, Inkscape will complain because we added quotes to the path itself:
** (inkscape-bin:9113): WARNING **: Can't open file: "/private/tmp/s p
a c e s/test.svg" (doesn't exist)
** (inkscape-bin:9113): WARNING **: Specified document "/private/tmp/s
p a c e s/test.svg" cannot be opened (does not exist or not a valid
SVG file)

3/ With my first patch, spaces in the path or even double quotes in
filenames are now properly handled.
Probably all of the conversion routines in grph-con.lua must be
patched similarly.

The Inkscape command line is:
inkscape "/private/tmp/s p a c e s/test.svg" --export-dpi=600
--export-pdf="/private/tmp/s p a c e s/m_k_i_v_test.svg.pdf"

I hope I was a bit clearer this time.
Thanks.


More information about the dev-context mailing list