Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

shlex.split usage for editor config with commands that have spaces #1151

Closed
zmoon opened this issue Jan 10, 2021 · 5 comments · Fixed by #1153
Closed

shlex.split usage for editor config with commands that have spaces #1151

zmoon opened this issue Jan 10, 2021 · 5 comments · Fixed by #1153
Assignees
Labels
bug Something isn't working

Comments

@zmoon
Copy link

zmoon commented Jan 10, 2021

Bug Report

Related to #581.

Environment

  • jrnl --diagnostic output:
    jrnl: v2.6
    Python: 3.9.1 (default, Jan  5 2021, 06:37:06)
    [GCC 5.4.0 20160609]
    OS: Linux 4.4.0-19041-Microsoft
    
  • Install method: pipx

Current Behavior vs Expected

I use a long Vim editor string with spaces ("vim -f +Goyo +Limelight \"+set spell linebreak\""). Used to work fine, but in 2.6 it doesn't (some commands are not recognized as commands, instead treats the last command as filename(s)).

Other Information

It looks like in

subprocess.call(shlex.split(config["editor"], posix=on_windows) + [tmpfile])

it should be posix=not on_windows or somesuch, like suggested here. I can confirm that

subprocess.call(shlex.split("vim -f +Goyo +Limelight \"+set spell linebreak\"", posix=True) + ["tmp"])

works fine in my environment, but

subprocess.call(shlex.split("vim -f +Goyo +Limelight \"+set spell linebreak\"", posix=False) + ["tmp"])

produces the same problem that I experience when I invoke jrnl.

@zmoon zmoon added 🆕 New! bug Something isn't working labels Jan 10, 2021
@KarimPwnz
Copy link
Contributor

I think this relates to #1096: mainly that shlex.split has weak Windows support.

numpy has dealt with this in numpy/numpy#12979, so we could import their command parser. However, I am not sure if we want to add another dependency.

@zmoon
Copy link
Author

zmoon commented Jan 10, 2021

@KarimPwnz note that my case here is Linux (though WSL). I did check that on_windows was indeed False. I think in this case posix=True should be passed to shlex.split, instead of posix=False.

@KarimPwnz
Copy link
Contributor

I missed that—you're absolutely right. I was under the assumption that jrnl set posix correctly, and at some point it did: e0177f4. But there was a regression: 631e08a.

@KarimPwnz
Copy link
Contributor

KarimPwnz commented Jan 10, 2021

Perhaps fixing that would also fix #1096.

@wren
Copy link
Member

wren commented Jan 16, 2021

Yup! Good catch, both of you!

We should:

  • move the shlex calls to a new function (so that it can be tested)
  • add a new on_posix function (also so that it can be tested) that probably just returns not on_windows
  • change all shlex calls in the code over to new function
  • add tests for each function

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants