Menu

#182 Any widget labels or string values are not escaped in Python code gen (backslash -> error!)

wont-fix
None
0.7.2
2016-09-20
2016-03-23
kxroberto
No

.. so for example I get this rendered by wxg0.7.2 (and 0.7.1) in init():

self.the_path = wx.TextCtrl(self, wx.ID_ANY, "C:\some\where\")

=> compile SyntaxError. luck! :) because many backslashes go through and produce false chars silently without clear error message.
Same with wx.StaticText label strings (and probably other things).

wxg0.6.3 at least made it correct like

self.the_path = wx.TextCtrl(self, wx.ID_ANY, "c:\\some\\where\\")

Related

Feature Requests: #39

Discussion

  • kxroberto

    kxroberto - 2016-03-23

    This patch in codegen.init.BaseLangCodeWriter.quote_str solves:

    --- _orig/__init__.py
    +++ ./__init__.py
    @@ -2180,14 +2180,14 @@
    
             # find and escape backslashes
             s = re.sub(
    -            r'\\\\+',
    +            r'\\+',
                 self._do_replace_backslashes,
                 s
                 )
             # the string will be embedded within double quotes, thereby double
             # quotes inside have to escape
             s = re.sub(
    -            r'\\?"',
    +            r'"',
                 self._do_replace_doublequotes,
                 s,
                 )
    

    I wonder why the language independent quotestr tries to (pre)escape things half way. And then the codegen.pycodegen.BaseLangCodeWriter._quote_str tryies 'additional' things. Doesn't the lang-specific quoter know best at all and do it all in one simple shift - e.g. python: repr(s.encode('ascii')) ; and on encoding failure: repr(s)

     
  • Carsten Grohmann

    • assigned_to: Carsten Grohmann
     
  • Carsten Grohmann

    • Description has changed:

    Diff:

    --- old
    +++ new
    @@ -1,11 +1,11 @@
     .. so for example I get this rendered by wxg0.7.2 (and 0.7.1) in __init__():
    -
    +~~~
     self.the_path = wx.TextCtrl(self, wx.ID_ANY, "C:\some\where\")
    -
    +~~~
     =>  compile SyntaxError. luck! :)  because many backslashes go through and produce false chars silently without clear error message.
     Same with wx.StaticText  label strings (and probably other things).
    
     wxg0.6.3 at least made it correct like
    -
    +~~~
     self.the_path = wx.TextCtrl(self, wx.ID_ANY, "c:\\some\\where\\")
    -
    +~~~
    
     
  • Carsten Grohmann

    Hi,

    The changed escaping algorithm is a trade-off between more and less escaping. The current decision is to do a minimal escaping.
    You can format your texts with tabs ("\t") and newline ("\n") characters currently.

    More escaping should be implemented in the application logic.

    Some thoughts about escaping:

    input

    text with\ttabs
    

    shown

    text with        tabs
    

    input

    text with a\nline break
    

    shown

    text with a
    line break
    

    But

    c:\newfile
    

    generates

    c:
    ewfile
    

    or

    c:\temp
    

    generates

    c:        emp
    

    What are your expectations? What do you suggest to handle this trade-off?

    Regards,
    Carsten

     
  • Carsten Grohmann

    I've transferred this topic into a new feature request [features:#39] to discuss and implement a solution that handles both approaches in a appropriate manner.

     

    Related

    Feature Requests: #39

  • Carsten Grohmann

    • status: open --> wont-fix
     
  • Carsten Grohmann

    • status: open --> wont-fix
     

Log in to post a comment.