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
ttk.Treeview "unmatched open brace in list" #60065
Comments
If you try to insert an item into the treeview, give it a tuple of values for the "values" attribute, and one of those values has unbalanced braces, you'll get an error "unmatched open brace in list" To reproduce: import Tkinter as tk
import ttk
root = tk.Tk()
tree = ttk.Treeview(root)
tree.insert("","end",values=("one","two","bam! {"))
root.mainloop() |
What behavior do you expect? By accident, I found your reply to this StackOverflow question. I take it from that that you think tkinter should be quoting curly braces found in strings. If that is what you mean, can you specify the set of characters that need to be escaped and in what contexts? |
What behavior do I expect? I expect it to not throw an error. I expect whatever string I give to be inserted into the widget unadulterated (ie: if I give the string "foo {" I expect to see "foo {" in the widget). Tkinter is effectively telling me "you have a Tcl syntax error". Since I'm programming in python I should be insulated from that, particularly since the error comes internally after Tkinter transforms my data. How Tkinter does it under the hood, I don't care. Tkinter should make sure that the data it passes to the Tcl interpreter is well-formed. |
I agree with Bryan. Further, if the string is being interpreted as Tcl, then this strikes me as a possible injection attack vector (although I'll admit to not having looked at the code to see how the Tcl code is being used and/or interpreted). |
I agree as well. The bigger question is, as Eric suggests, is this the only such case when mapping between Python and Tcl elements? Since Bryan is a well-known Tcl and Tkinter expert, his insights on that would be very useful. |
I gave myself an hour or so to play around with this, and the crux of the matter seems to be in the function
What is needed is to create a bona fide tcl list element according to the rules of Tcl. I tried a hack where I simply escaped all problem characters, so instead of returning What I think ttk needs (and may already exist somewhere in the Tkinter world; I haven't looked...) is a function that takes a tuple and converts it to a canonical list. Then, the places that do something ad hoc can all call this one function. For more information on the gory details of the string representation of a list see http://www.tcl.tk/cgi-bin/tct/tip/407.html |
Just tested on 3.3 and this still happens with that version of Tkinter, which should mean the same happens in 3.2 and 3.4. |
I think this is a case of faulty over-engineering in the ttk module. The following works just fine (imports converted to Python3): import tkinter as tk
import tkinter.ttk as ttk
root = tk.Tk()
tree = ttk.Treeview(root, columns="1 2 3")
tree.tk.call(tree, "insert", "", "end" , "-values", ("one","two","bam! {"))
tree.grid()
root.mainloop() |
Here is a patch for right quoting of arguments before concatenation. Thanks Bryan Oakley for the analysis. |
Patch updated. |
Patch updated. Added additional tests for ttk.Combobox (see bpo-11290). |
Patch for 2.7 added. |
I consider myself the main responsible for this bug, so if the current patch (which I didn't look at) passes all tests, doesn't slow things up (unlikely, I would think) and also works with some more involved styling code then I'm fine with it. These formatting functions were added to the ttk module to make it easier to create and adjust styles using Python. It wouldn't be possible without them unless the person basically coded in Tcl while in Python. These functions ended up being used in other places (as was noticed here) for convenience. All in all, I'm glad someone else is using the module, reporting, and improving it. |
Have you reviewed the patch? Is it good? |
New changeset 411bb75be5d1 by Serhiy Storchaka in branch '3.2': New changeset 927352d7e994 by Serhiy Storchaka in branch '3.3': New changeset 340e97ebe911 by Serhiy Storchaka in branch 'default': New changeset 917ae14831ec by Serhiy Storchaka in branch '2.7': |
Fixed. Thank you for report, Bryan Oakley. |
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: