Commit 5cb289f
Refactor Git.execute() command docstring per gitpython-developers#2146
gitpython-developers#2146 identifies two issues with gitpython-developers#2144's :param command: rewrite,
which this fixes by reworking the block as three paragraphs:
1. Description and platform handling. A sequence is recommended.
For strings: on Unix-like systems the whole string is the
program name (so multi-word strings raise GitCommandNotFound);
on Windows the OS parses the string itself, so multi-word
strings can work there but are not portable. This corrects
gitpython-developers#2144's claim that with shell=False the string "is passed as a
single executable name to subprocess.Popen" -- accurate on
Unix-like systems, but on Windows subprocess.Popen forwards the
string to CreateProcessW and Windows command-line parsing
produces argv. The portability problem is the user-visible one,
so the docstring leads with that framing.
2. shell=True / Git.USE_SHELL warning. The shell interprets
metacharacters such as ;, |, &, and $(...) as syntax;
untrusted text in the command can then execute arbitrary OS
commands. Cross-references USE_SHELL for the long-form
discussion (which has the attack examples and history).
3. shlex.split caveat. Far safer than shell=True (so gitpython-developers#2144's
harm-reduction note is preserved), but qualified: it parses
POSIX shell syntax and is still unsafe for anything but fixed,
fully trusted strings. Calls out the f-string-then-shlex.split
anti-pattern explicitly -- whitespace or quoting in an untrusted
interpolated value can still inject arguments, so shlex.split
should not be recommended as a default tokenization tool. For
untrusted input, build the sequence yourself.
Removes gitpython-developers#2144's hedged "possible security implications" wording
and its implicit recommendation of shlex.split as a general string-
to-argv splitter, in favor of named mechanisms and a narrow
qualified mention. Documentation only; behavior is unchanged.
Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>1 parent 7b83f7a commit 5cb289f
1 file changed
Lines changed: 20 additions & 10 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1131 | 1131 | | |
1132 | 1132 | | |
1133 | 1133 | | |
1134 | | - | |
1135 | | - | |
1136 | | - | |
1137 | | - | |
1138 | | - | |
1139 | | - | |
1140 | | - | |
1141 | | - | |
1142 | | - | |
1143 | | - | |
| 1134 | + | |
| 1135 | + | |
| 1136 | + | |
| 1137 | + | |
| 1138 | + | |
| 1139 | + | |
| 1140 | + | |
| 1141 | + | |
| 1142 | + | |
| 1143 | + | |
| 1144 | + | |
| 1145 | + | |
| 1146 | + | |
| 1147 | + | |
| 1148 | + | |
| 1149 | + | |
| 1150 | + | |
| 1151 | + | |
| 1152 | + | |
| 1153 | + | |
1144 | 1154 | | |
1145 | 1155 | | |
1146 | 1156 | | |
| |||
0 commit comments