<div dir="ltr"><br><div class="gmail_extra"><br><div class="gmail_quote">On Tue, Aug 11, 2015 at 2:25 PM, Joonas Liik <span dir="ltr"><<a href="mailto:liik.joonas@gmail.com" target="_blank">liik.joonas@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div class="gmail_extra">I would rather think of this as an opportunity to help avoid injection vectors.</div></div></blockquote><div><br></div><div>you get an "F" grade/letter/mark every time you build an f-string</div><div>without defining what the user-supplied input and destination outputs</div><div>could/would be.</div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div class="gmail_extra"><br></div><div class="gmail_extra">if there was a separate.. . interpolation provider ..</div><div class="gmail_extra">then something like</div><div class="gmail_extra"><br><span style="color:rgb(80,0,80);font-size:12.8px">os.system('dosomething {a} </span><span style="color:rgb(80,0,80);font-size:12.8px">{b} </span><span style="color:rgb(80,0,80);font-size:12.8px">{c}</span><span style="color:rgb(80,0,80);font-size:12.8px">'.format(...))</span></div><div class="gmail_extra"><div class="gmail_extra"><br></div><div class="gmail_extra">could be written as ( !cmd here being a special type of f-string that does command line escaping, borrowing syntax from another thread a few days ago..)</div><div class="gmail_extra"><br><span style="color:rgb(80,0,80);font-size:12.8px">os.sytem(!cmd'dosomething {a} </span><span style="color:rgb(80,0,80);font-size:12.8px">{b} </span><span style="color:rgb(80,0,80);font-size:12.8px">{c}</span><span style="color:rgb(80,0,80);font-size:12.8px">')</span></div></div></div></blockquote><div><br></div><div>sarge.run('do something {0} {1} {2}', a, b, c) is currently supported</div><div>(and could/should be stdlib IMHO) <a href="https://sarge.readthedocs.org/en/latest/overview.html#why-not-just-use-subprocess">https://sarge.readthedocs.org/en/latest/overview.html#why-not-just-use-subprocess</a>.</div><div><br></div><div>  * (again, sorry) this adds ~subprocess compat to sarge: <a href="https://bitbucket.org/vinay.sajip/sarge/pull-requests/1/enh-add-call-check_call-check_output">https://bitbucket.org/vinay.sajip/sarge/pull-requests/1/enh-add-call-check_call-check_output</a> ("ENH: Add call, check_call, check_output, CalledProcessError, expect_returncode")</div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div class="gmail_extra"><div class="gmail_extra"><span style="color:rgb(80,0,80);font-size:12.8px"><br></span></div><div class="gmail_extra"><span style="color:rgb(80,0,80);font-size:12.8px">This is both shorter and more resilient to injections.</span></div><div class="gmail_extra"><font color="#500050"><span style="font-size:12.8px">Essentially it feels like you annotate a string as "this will be executed on the command line" and the interpolation adapts.</span></font></div></div></div></blockquote><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div class="gmail_extra"><div class="gmail_extra"><br></div><div class="gmail_extra">this would make doing the right thing the same as doing the easy thing and this would be good overall, no?</div><div class="gmail_extra">I don't know about you, but i dont know by heart how to escape arbitrary user input and deal with all of the corner cases.</div></div></div></blockquote><div><br></div><div>So, IPython/Jupyter understands _repr_html_ (_repr_*_) methods,</div><div>IDK why we couldn't have e.g.  _repr_shell_path_, _repr_shell_cmdarg_,</div><div>_repr_sql_sqlite_reserved_keywords_.</div><div><br></div><div>Representing things for an output format which is expressed as a string</div><div>but has control characters</div><div>in order to separate data and code.</div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div class="gmail_extra"><div class="gmail_extra"><br></div><div class="gmail_extra">yes, you can do this more safely with Popen.. but that is quite a bit more effort.</div><div class="gmail_extra">also often times there is no such alternative or it is very unweildy (sql land this happens more often)</div></div></div></blockquote><div><br></div><div>POSIX exec accepts a tuple (and does not parse ';' or '--').</div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div class="gmail_extra"><div class="gmail_extra"><br></div><div class="gmail_extra"><br></div></div></div>
<br>_______________________________________________<br>
Python-ideas mailing list<br>
<a href="mailto:Python-ideas@python.org">Python-ideas@python.org</a><br>
<a href="https://mail.python.org/mailman/listinfo/python-ideas" rel="noreferrer" target="_blank">https://mail.python.org/mailman/listinfo/python-ideas</a><br>
Code of Conduct: <a href="http://python.org/psf/codeofconduct/" rel="noreferrer" target="_blank">http://python.org/psf/codeofconduct/</a><br></blockquote></div><br></div></div>