Opened 10 years ago
Closed 10 years ago
#4621 closed defect (fixed)
icon entities cannot be unicode or Rsvg chokes
Reported by: | walter | Owned by: | |
---|---|---|---|
Priority: | Unspecified by Maintainer | Milestone: | Unspecified |
Component: | Sugar | Version: | Git as of bugdate |
Severity: | Unspecified | Keywords: | AU1B |
Cc: | godiard, dnarvaez | Distribution/OS: | Fedora |
Bug Status: | Unconfirmed |
Description
_SVGLoader in icon.py processes entities in order to map Sugar icons into user colors. It then calls Rsvg to generate the icon SVG. All is well if the icon colors are type str, but if they are type unicode, Rsvg generates an error.
In the Comments class in Sugar Journal expandedentry.py icon colors are extracted from metadata using json.loads. This call (at least on F19) converts all strings to type unicode. Hence the comment icons are not rendering since they trigger the problem described above.
A simple fix is to convert the icon colors to str with encode('ascii', 'replace') after the call from json.loads. A more robust fix might be to test for unicode in icon.py.
I've prepared both patches. Which would be best?
Change History (9)
comment:1 Changed 10 years ago by godiard
- Cc godiard added; gonzalo removed
comment:2 Changed 10 years ago by godiard
comment:3 Changed 10 years ago by walter
Please review https://github.com/sugarlabs/sugar-toolkit-gtk3/pull/33
comment:4 Changed 10 years ago by dnarvaez
Can you post the error please? I'd expect pygobject to autoconvert the string.
comment:5 Changed 10 years ago by dnarvaez
- Cc dnarvaez added
Answering myself:
TypeError: Item 0: Must be number or single byte string, not unicode
comment:6 Changed 10 years ago by godiard
The fix have sense, please push.
comment:7 Changed 10 years ago by dnarvaez
(The reason pygobject is not taking unicode as it normally does is that this function is explicitly requiring an uint8 array, not a string)
comment:8 Changed 10 years ago by walter
I've moved the conversion to where the entities are first mapped in icon.py. New PR coming in a few minutes.
comment:9 Changed 10 years ago by Walter Bender
- Resolution set to fixed
- Status changed from new to closed
Ensure entity value is type str
There are times when the entity value passed in for substitution
is of type unicode. This causes Rsvg to fail when processing the
SVG. This patch checks for unicode and converts it to utf-8.
Fixes #4621
Changeset: ec5f064c10d902958eb49035b2c35f91a7055267
This issue has already happen in other places, should be good solve it on icon.py