godot
godot copied to clipboard
Fix .blend files with quotation marks in filename fail to import
Fixes #78447
The main problem was using c_escape for paths which add \ to ' resulting to an invalid path since \ is not an escape character in XML.
Also, I added a parse and print for faultString if an error occur in Blender/Python.
I also fixed the problem where every call returned 'cannot marshal None unless allow_none is enabled' because the Python method export_gltf did not return a value.
Tested:
- Filename with
'. - Filename with accents (non standard characters).
- Export without RPC for filename containing
'(do_import_direct).
Example of the blender error message from RPC response:
Is there any escaping being done to the request payloads that we send now? Or unescaping for the responses?
Xml needs to escape characters < and & in text and same for unescaping the response error text. So < and & respectively.
Note that the String class has xml_escape and xml_unescape if we need to ensure proper escaping.
The values are already escaped in dict_to_xmlrpc and this function is used to created the XML payload.
It is important to not escape strings in parameters_map and request_options because they will be double escaped. And more, the same dictionary is used for rpc call (xml) in do_import_rpc and for direct call in do_import_direct where the values are converted in python and escaped in dict_to_python. Another c_escape is made in dict_to_python that was causing a double escape for the ' when not in RPC.
Just to be sure, I tested with a &:
I just add a little problem with this PR on my computer. I had 2 versions on Godot running, one with this modification, and one without. If the version without did a blender import first, blender was started with the old script that returns 'cannot marshal None unless allow_none is enabled'. When I import a file in Godot with this PR included, the error is trapped and the importation fails. I had to close the old version before it works again. Both version use the same blender process with the old script.
I think I should discard the error 'cannot marshal None unless allow_none is enabled' just to prevent issues for users using different versions of Godot? What do you think?
I think I should discard the error 'cannot marshal None unless allow_none is enabled' just to prevent issues for users using different version of Godot?
Not sure if it's worth adding this check, for the rare case of having multiple Godot instances running and using Blender imports on both...
I suppose if the check is simple enough to implement, documented with a comment as to why it's needed, it won't do any harm to add it. At least the error message is hard-coded on Python's side ^^
There you go, I just added a check to discard the error 'cannot marshal None unless allow_none is enabled'.
Thanks @Hilderin for the fix and everyone else for the in-depth review!