Re: [PATCH] Unit tests for function calling MathML converters (Re: Warn about shell-expansion in the docstring of org-latex-to-html-convert-command)

2024-04-01 Thread Ihor Radchenko
Max Nikulin writes: >> I have a concern about this test - it will not work on windows or in > > I do not mind to add > > (skip-unless (not (memq system-type '(ms-dos windows-nt > >> non-standard system shells. We should probably disable the test unless >> "printf" can be evaluated in the

Re: Warn about shell-expansion in the docstring of org-latex-to-html-convert-command

2024-04-01 Thread Ihor Radchenko
Max Nikulin writes: >> I have incorporated the above suggestions into the attached version of >> the patch. > > Thanks, I have not tried the updated patch in action, but it looks like > what I expect. > I would consider explicit mention of stripping quotes > ... I incorporated your suggestions

Re: [PATCH] Unit tests for function calling MathML converters (Re: Warn about shell-expansion in the docstring of org-latex-to-html-convert-command)

2024-04-01 Thread Max Nikulin
On 31/03/2024 15:27, Ihor Radchenko wrote: Max Nikulin writes: +(ert-deftest test-org/format-latex-as-html () + "Test shell special characters escaping in `org-format-latex-as-html'." + (let ((org-latex-to-html-convert-command + "printf \"\" %i")) I have a concern about this test -

Re: Warn about shell-expansion in the docstring of org-latex-to-html-convert-command

2024-04-01 Thread Max Nikulin
On 31/03/2024 15:25, Ihor Radchenko wrote: Max Nikulin writes: I think it is in the right direction. - Manual needs update as well. - I would explicitly stress that quotes causes undefined or even dangerous behavior. See e.g. the last paragraph https://specifications.freedesktop.org/desktop-ent

Re: [PATCH] Unit tests for function calling MathML converters (Re: Warn about shell-expansion in the docstring of org-latex-to-html-convert-command)

2024-03-31 Thread Ihor Radchenko
Max Nikulin writes: > Is second attachment appropriate to fix the issue or it has some > undesired effects. Thanks! > +(ert-deftest test-org/format-latex-as-html () > + "Test shell special characters escaping in `org-format-latex-as-html'." > + (let ((org-latex-to-html-convert-command > +

Re: Warn about shell-expansion in the docstring of org-latex-to-html-convert-command

2024-03-31 Thread Ihor Radchenko
Max Nikulin writes: >> Attaching tentative patch that fixes the problem. > > I think it is in the right direction. > - Manual needs update as well. > - I would explicitly stress that quotes causes undefined or even > dangerous behavior. See e.g. the last paragraph > https://specifications.freede

Re: Warn about shell-expansion in the docstring of org-latex-to-html-convert-command

2024-03-19 Thread Ihor Radchenko
Max Nikulin writes: >> https://git.savannah.gnu.org/cgit/emacs/org-mode.git/commit/?id=b338a9069 > > `with-temp-buffer' makes `kill-buffer' unnecessary. Oops. https://git.savannah.gnu.org/cgit/emacs/org-mode.git/commit/?id=4f548f948 -- Ihor Radchenko // yantar92, Org mode contributor, Learn mo

Re: Warn about shell-expansion in the docstring of org-latex-to-html-convert-command

2024-03-19 Thread Max Nikulin
On 19/03/2024 21:49, Ihor Radchenko wrote: but I do not see downsides of using `insert-file-contents' instead of `find-file-noselect' and not running `find-file-hook' in this particular case (other cases in Org tree appears to be fine from a quick glance). https://git.savannah.gnu.org/cgit/ema

Re: Warn about shell-expansion in the docstring of org-latex-to-html-convert-command

2024-03-19 Thread Ihor Radchenko
Ihor Radchenko writes: >> It is a bug in Org that some hooks are called when just file content is >> necessary. > > I would not necessarily call it a bug, but I do not see downsides of > using `insert-file-contents' instead of `find-file-noselect' and not > running `find-file-hook' in this parti

Re: Warn about shell-expansion in the docstring of org-latex-to-html-convert-command

2024-03-19 Thread Ihor Radchenko
Max Nikulin writes: >>> On 12/03/2024 20:03, Ihor Radchenko wrote: >>> - '%i' and "%i" in any position including e.g. --option='%i' and >>> protocol:"%i" >>> - 'something%i' and "something%i" surrounded by spaces or at the end of >>> command but with no spaces in "something". >> >> I am not conf

Re: Warn about shell-expansion in the docstring of org-latex-to-html-convert-command

2024-03-18 Thread Max Nikulin
On 15/03/2024 20:49, Ihor Radchenko wrote: Max Nikulin writes: On 12/03/2024 20:03, Ihor Radchenko wrote: - '%i' and "%i" in any position including e.g. --option='%i' and protocol:"%i" - 'something%i' and "something%i" surrounded by spaces or at the end of command but with no spaces in "somethin

Re: Warn about shell-expansion in the docstring of org-latex-to-html-convert-command

2024-03-15 Thread Ihor Radchenko
Max Nikulin writes: > On 12/03/2024 20:03, Ihor Radchenko wrote: >> Max Nikulin writes: >>> It is trivial to cause shell failure when single quotes are used around >>> %i. I am in doubts concerning double quotes. Perhaps stripping them is >>> more reliable. >> >> May you list the cases to you pr

Re: Warn about shell-expansion in the docstring of org-latex-to-html-convert-command

2024-03-13 Thread Max Nikulin
On 12/03/2024 20:03, Ihor Radchenko wrote: Max Nikulin writes: It is trivial to cause shell failure when single quotes are used around %i. I am in doubts concerning double quotes. Perhaps stripping them is more reliable. May you list the cases to you propose to recognize? Sun, 25 Feb 2024 17

Re: Warn about shell-expansion in the docstring of org-latex-to-html-convert-command

2024-03-12 Thread Ihor Radchenko
Max Nikulin writes: >> Even stripping quotes is unreliable when we use the example from >> docstring: 'literal:%i'. > > My idea is to recognize this case. If stripping is not performed then it > is necessary to detect if user command is safe. Otherwise apostrophe in > a formula (even after esca

[PATCH] Unit tests for function calling MathML converters (Re: Warn about shell-expansion in the docstring of org-latex-to-html-convert-command)

2024-03-09 Thread Max Nikulin
On 09/03/2024 22:23, Max Nikulin wrote: On 08/03/2024 18:16, Ihor Radchenko wrote: Attaching tentative patch that fixes the problem. I propose to add unit tests, see first attachment. I have tried to add some unit tests, but I faced an issue with `org-create-math-formula'. It creates tempor

Re: Warn about shell-expansion in the docstring of org-latex-to-html-convert-command

2024-03-09 Thread Max Nikulin
On 08/03/2024 18:16, Ihor Radchenko wrote: Max Nikulin writes: I decided not to introduce stdin. User can always use echo %i | ... instead. printf "%%s" %i should be safer. However in this particular case, input that may be recognized like echo options ("-n") should be wrapped with LaTeX del

Re: Warn about shell-expansion in the docstring of org-latex-to-html-convert-command

2024-03-08 Thread Ihor Radchenko
Max Nikulin writes: >>> It should be more reliable to pass fragment to command stdin. It can be >>> done if %i is missed in `org-latex-to-html-convert-command'. >> >> I agree that it will be more reliable to shell-escape argument. >> However, I am concerned that escaping may break certain uses l

Re: Warn about shell-expansion in the docstring of org-latex-to-html-convert-command

2024-03-05 Thread Max Nikulin
On 25/02/2024 17:41, Max Nikulin wrote: Max Nikulin writes: So `shell-quote-argument' is necessary and quotes around %i must be stripped similar to %s in mailcap entries in `org-open-file'. ... Please, revert the commit that added a misleading recommendation. ... It should be more reliable

Re: Warn about shell-expansion in the docstring of org-latex-to-html-convert-command

2024-02-26 Thread Max Nikulin
On 26/02/2024 17:48, Ihor Radchenko wrote: Max Nikulin writes: Something weird may be executed in the case of sufficiently complex equations. It should be more reliable to pass fragment to command stdin. It can be done if %i is missed in `org-latex-to-html-convert-command'. I agree that it

Re: Warn about shell-expansion in the docstring of org-latex-to-html-convert-command

2024-02-26 Thread Ihor Radchenko
Max Nikulin writes: > (let ((org-latex-to-html-convert-command > "printf '%%s' '%i'")) >(org-format-latex-as-html "$f' = df/dx$")) > "/bin/bash: -c: line 1: unexpected EOF while looking for matching `'' > " > > Something weird may be executed in the case of sufficiently complex > equ

Re: Warn about shell-expansion in the docstring of org-latex-to-html-convert-command

2024-02-25 Thread Max Nikulin
On 23/02/2024 19:46, Ihor Radchenko wrote: Max Nikulin writes: On 19/02/2024 02:36, Martin Edström wrote: +Since this is a shell-command, remember to use single-quotes +around \\='%i\\=', not double-quotes! Else a math fragment such +as \"$y = 200$\" gets butchered into only \" = 200\"." I

Re: Warn about shell-expansion in the docstring of org-latex-to-html-convert-command

2024-02-24 Thread Martin Edström
Ah yes. My custom Node script (which I hope it's OK to paste below) strips the beginnings and ends of the input. I suppose that it could be done already on the Elisp side, which would take care of interpreting the $-signs as envvars too. const katex = require('katex') let input = process.argv[2].t

Re: Warn about shell-expansion in the docstring of org-latex-to-html-convert-command

2024-02-24 Thread Martin Edström
And ignore my suggestion about stripping input on the Elisp side. Didn't think that through. On Wed, 21 Feb 2024 at 16:04, Martin Edström wrote: > > Actually, I agree about your test case, that looks like it'd cause a problem. > > So we patch the function to use `shell-quote-argument'? > > On Wed

Re: Warn about shell-expansion in the docstring of org-latex-to-html-convert-command

2024-02-24 Thread Martin Edström
Actually, I agree about your test case, that looks like it'd cause a problem. So we patch the function to use `shell-quote-argument'? On Wed, 21 Feb 2024 at 15:38, Max Nikulin wrote: > > On 19/02/2024 02:36, Martin Edström wrote: > > +Since this is a shell-command, remember to use single-quotes

Re: Warn about shell-expansion in the docstring of org-latex-to-html-convert-command

2024-02-23 Thread Ihor Radchenko
Max Nikulin writes: > On 19/02/2024 02:36, Martin Edström wrote: >> +Since this is a shell-command, remember to use single-quotes >> +around \\='%i\\=', not double-quotes! Else a math fragment such >> +as \"$y = 200$\" gets butchered into only \" = 200\"." > > I am afraid, the code, not the docs

Re: Warn about shell-expansion in the docstring of org-latex-to-html-convert-command

2024-02-21 Thread Max Nikulin
On 19/02/2024 02:36, Martin Edström wrote: +Since this is a shell-command, remember to use single-quotes +around \\='%i\\=', not double-quotes! Else a math fragment such +as \"$y = 200$\" gets butchered into only \" = 200\"." I am afraid, the code, not the docstring must be fixed. I have not t

Re: Warn about shell-expansion in the docstring of org-latex-to-html-convert-command

2024-02-19 Thread Ihor Radchenko
Martin Edström writes: > Tests passed (14 SKIPPED), compiled fine. I've made no prior > contributions and this changes 5 lines. I'm ok if you want to rephrase > it in any way. Applied onto main, with amendments. https://git.savannah.gnu.org/cgit/emacs/org-mode.git/commit/?id=a8443f2c7 Thanks fo

Re: Warn about shell-expansion in the docstring of org-latex-to-html-convert-command

2024-02-18 Thread Martin Edström
Here you go! Tests passed (14 SKIPPED), compiled fine. I've made no prior contributions and this changes 5 lines. I'm ok if you want to rephrase it in any way. Martin On Sun, 18 Feb 2024 at 19:56, Martin Edström wrote: > > I will try to do a patch, thanks for the link. Stay tuned. > > On Sun,

Re: Warn about shell-expansion in the docstring of org-latex-to-html-convert-command

2024-02-18 Thread Martin Edström
I will try to do a patch, thanks for the link. Stay tuned. On Sun, Feb 18, 2024 at 15:06 Ihor Radchenko wrote: > Martin Edström writes: > > > I've just been struggling with my custom setting for > > `org-latex-to-html-convert-command` outputting many math snippets > > wrong. The fault was mine:

Re: Warn about shell-expansion in the docstring of org-latex-to-html-convert-command

2024-02-18 Thread Ihor Radchenko
Martin Edström writes: > I've just been struggling with my custom setting for > `org-latex-to-html-convert-command` outputting many math snippets > wrong. The fault was mine: I didn't correctly shell-quote the input. > I propose to add a warning in the docstring, because many people will > trip t

Warn about shell-expansion in the docstring of org-latex-to-html-convert-command

2024-02-16 Thread Martin Edström
I've just been struggling with my custom setting for `org-latex-to-html-convert-command` outputting many math snippets wrong. The fault was mine: I didn't correctly shell-quote the input. I propose to add a warning in the docstring, because many people will trip the same problem. The thing is that