<p dir="ltr">On Aug 10, 2015 11:33 AM, "Barry Warsaw" <<a href="mailto:barry@python.org">barry@python.org</a>> wrote:<br>
><br>
> On Aug 11, 2015, at 03:26 AM, Steven D'Aprano wrote:<br>
><br>
> >I think I would be happy with f-strings, or perhaps i-strings if we use<br>
> >Nick's ideas about internationalisation, and limit what they can evaluate to<br>
> >name lookups, attribute lookups, and indexing, just like format().<br>
><br>
> I still think you really only need name lookups, especially for an i18n<br>
> context.  Anything else is just overkill, YAGNI, potentially error prone, or<br>
> perhaps even harmful.<br>
><br>
> Remember that the translated strings usually come from only moderately (if at<br>
> all) trusted and verified sources, so it's entirely possible that a malicious<br>
> translator could sneak in an exploit, especially if you're evaluating<br>
> arbitrary expressions.  If you're only doing name substitutions, then the<br>
> worst that can happen is an information leak, which is bad, but won't<br>
> compromise the integrity of say a server using the translation.<br>
><br>
> Even if the source strings avoid the use of expressions, if the feature is<br>
> available, a translator could still sneak something in.  That pretty much<br>
> makes it a non-starter for i18n, IMHO.<br>
><br>
> Besides, any expression you have to calculate can go in a local that will get<br>
> interpolated.  The same goes for any !r or other formatting modifiers.  In an<br>
> i18n context, you want to stick to the simplest possible substitution<br>
> placeholders.</p>
<p dir="ltr">IIUC what Nick contemplates in PEP 501 is that when you write something like<br>
  i"I am ${self.age}"<br>
then the python runtime would itself evaluate self.age and pass it on to the i18n machinery to do the actual substitution; the i18n machinery wouldn't even contain any calls to eval. The above string could be translated as<br>
  i"Tengo ${self.age} años"<br>
but<br>
  i"Tengo ${self.password} años"<br>
would be an error, because the runtime did not provide a value for self.password. So while arbitrarily complex expressions are allowed (at least as far as the language is concerned -- a given project or i18n toolkit could impose additional policy restrictions), by the time the interpolation machinery runs they'll effectively have been reduced to local variables with funny multi-token names.</p>
<p dir="ltr">This pretty much eliminates all the information leak and exploit concerns, AFAICT. From your comments about having to be careful about attribute chasing, it sounds like it might even be more robust than current flufl.i18n in this regard...?</p>
<p dir="ltr">-n</p>