wspr / will2e

Assorted (somewhat historic) LaTeX2e packages
0 stars 3 forks source link

ifplatform: filename escaping issue? #12

Open Arinerron opened 1 year ago

Arinerron commented 1 year ago

Unfortunately I can't share reproduction steps, but thought I'd note there seems to be some kind of argument escaping issue:

Rc files read:
  NONE
Latexmk: Run number 1 of rule 'xelatex'
This is XeTeX, Version 3.141592653-2.6-0.999993 (TeX Live 2022/dev/Debian) (preloaded format=xelatex)
 \write18 enabled.
entering extended mode
uname: extra operand 'REDACTED'
Try 'uname --help' for more information.
system returned with code 256
Latexmk: Log file says no output from latex
Latexmk: For rule 'xelatex', no output was made
Collected error summary (may duplicate other messages):
  xelatex: Command for 'xelatex' gave return code 1
      Refer to 'REDACTED.log' for details
Latexmk: Use the -f option to force complete processing,
runsystem(uname -s > ""REDACTED".w18")...executed.

/usr/share/texlive/texmf-dist/tex/latex/ifplatform/ifplatform.sty:92: Package catchfile Error: File `"REDACTED".w18' not found.

See the catchfile package documentation for explanation.
Type  H <return>  for immediate help.
 ...                                              

l.92     \CatchFileDef\@tempa{\ip@file}{}

The "REDACTED" filename has spaces in it which probably has something to do with it. I never experienced this issue till I added "-shell-escape" arg to latexmk in our build process.

muzimuzhi commented 1 year ago

When the input filename has spaces, like spaces in filename.tex, \jobname is already quoted ("spaces in filename"). But in various places ifplatform adds another pair of quotes. This resulted in executing commands with extra operand, like in

runsystem(uname -s > ""REDACTED".w18")...executed.

https://github.com/wspr/will2e/blob/a6c00f55826fbeb365d2018544536759a9b45dc7/ifplatform/ifplatform.dtx#L246 https://github.com/wspr/will2e/blob/a6c00f55826fbeb365d2018544536759a9b45dc7/ifplatform/ifplatform.dtx#L376

You can use expl3 functions \sys_if_platform_unix:TF and \sys_if_platform_windows:TF to replace ifplatform, also see #5.

If ifplatform is loaded by another package, like minted, here's an emulation of \ifwindows needed by minted.

\documentclass{article}
\ExplSyntaxOn
% pretend ifplatform is loaded
\tl_const:cn {ver@ifplatform.sty} {0000-00-00}
\newif\ifwindows
\sys_if_platform_windows:TF {\windowstrue} {\windowsfalse}
\ExplSyntaxOff
\usepackage{minted}

\begin{document}
\begin{minted}{tex}
  $a + b = c^2$
\end{minted}
content
jameshbailie commented 8 months ago

Thank you @muzimuzhi I had the same error and your workaround fixed it!

user202729 commented 7 months ago

@wspr Consider fixing this issue? On Linux, this patch fixes it for me:

--- ifplatform.sty      2024-03-04 04:45:05.830042206 +0700
+++ /usr/share/texmf-dist/tex/latex/ifplatform/ifplatform.sty   2024-03-04 04:46:58.536711651 +0700
@@ -51,17 +51,17 @@
 \else
   \IfFileExists{nul:}{\@ip@nix@false}{\@ip@nix@true}
   \IfFileExists{/dev/null}{\windowsfalse}{\windowstrue}
-  \edef\ip@windows@echo@test{echo \string# > "\ip@file"}
+  \edef\ip@windows@echo@test{echo \string# > \ip@file}
   \def\ip@backupplan{%
     \IfFileExists{\ip@file}{%
       \PackageWarningNoLine{ifplatform}{^^J \space\space\space
-        Please delete the file "\ip@file" and try again%
+        Please delete the file \ip@file and try again%
       }%
       \ip@cantdecide
     }{%
       \ShellEscape{\ip@windows@echo@test}%
       \IfFileExists{\ip@file}{%
-        \ShellEscape{del "\ip@file"}%
+        \ShellEscape{del \ip@file}%
         \windowstrue
       }{%
         \@ip@nix@true
@@ -88,9 +88,9 @@
 \def\ip@only@six#1#2#3#4#5#6#7\@nil{#1#2#3#4#5#6}
 \if@ip@nix@\ifshellescape
   \ifwindows\else
-    \ShellEscape{uname -s > "\ip@file"}
+    \ShellEscape{uname -s > \ip@file}
     \CatchFileDef\@tempa{\ip@file}{}
-    \ShellEscape{rm -- "\ip@file"}
+    \ShellEscape{rm -- \ip@file}
     \edef\@tempa{\expandafter\zap@space\@tempa\@empty}
     \def\@tempb{Linux}
     \ifx\@tempa\@tempb

Assume \jobname is also quoted on Windows and Mac etc. if it has a space, this should be safe