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

Don't use a shell to call inkscape #1512

Merged
merged 3 commits into from Jun 7, 2021
Merged

Don't use a shell to call inkscape #1512

merged 3 commits into from Jun 7, 2021

Conversation

yuvipanda
Copy link
Contributor

Python generally recommends against using shell=True
when calling
subprocesses (https://docs.python.org/3/library/subprocess.html#security-considerations).
This also causes issues with shell metacharacters (see
#1469). I'm also
not entirely sure that the shell command is fully trustable

  • I don't know where {to_filename} and {from_filename} are
    from. Rest of nbconvert also prefers using lists instead
    of strings to call commands.

svg2pdf also uses a command instead of a string now. We leave
the old string implementation alone for backwards compatibility,
although I'd really prefer to remove it.

We don't need the quotes set up in
#1469,
since using a list automatically deals with that.

Python generally recommends against using `shell=True`
when calling
subprocesses (https://docs.python.org/3/library/subprocess.html#security-considerations).
This also causes issues with shell metacharacters (see
#1469). I'm also
not entirely sure that the shell command *is* fully trustable
- I don't know where {to_filename} and {from_filename} are
from. Rest of nbconvert also prefers using lists instead
of strings to call commands.

svg2pdf also uses a command instead of a string now. We leave
the old string implementation alone for backwards compatibility,
although I'd really prefer to remove it.

We don't need the quotes set up in
#1469,
since using a list automatically deals with that.
# For backwards compatibility with specifying strings
# Okay-ish, since the string is trusted
full_cmd = self.command.format(*template_vars)
subprocess.call(full_cmd, shell=isinstance(str))
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

must be isinstance(full_cmd, str)

@@ -62,26 +62,37 @@ def _inkscape_version_default(self):
raise RuntimeError("Unable to find inkscape executable --version")
return output.decode('utf-8').split(' ')[1]

command = Unicode(
help="""The command to use for converting SVG to PDF
# FIXME: Deprecate passing a list here
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't this be

Suggested change
# FIXME: Deprecate passing a list here
# FIXME: Deprecate passing a string here

@yuvipanda
Copy link
Contributor Author

@agoose77 @technic fixed!

Copy link
Contributor

@MSeal MSeal left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tested changed merged with main. Let's get this in and try to double check the alpha is working for folks on Windows more rigerously after that

@MSeal MSeal merged commit 5a938a9 into jupyter:main Jun 7, 2021
@MSeal MSeal added this to the 6.1 milestone Jun 8, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants