Opened 9 years ago

Closed 9 years ago

Last modified 9 years ago

#1034 closed defect (fixed)

"addmedia" command doesn't handle UTF8 titles/descriptions

Reported by: Matt Molyneaux Owned by:
Priority: critical Milestone:
Component: programming Keywords:
Cc: Christopher Allan Webber, berkerpeksag Parent Tickets:

Description

When adding media via the commandline, UTF8 characters in either --title or --description cause a UnicodeDecodeError:

(mediagoblin)[gmg@dichromate mediagoblin]$ gmg addmedia moggers87 doge.png --title "test ß"
Traceback (most recent call last):
  File "/home/gmg/mediagoblin/bin/gmg", line 9, in <module>
    load_entry_point('mediagoblin==0.7.0', 'console_scripts', 'gmg')()
  File "/home/gmg/mediagoblin/mediagoblin/gmg_commands/__init__.py", line 124, in main_cli
    args.func(args)
  File "/home/gmg/mediagoblin/mediagoblin/gmg_commands/addmedia.py", line 95, in addmedia
    title=maybe_unicodeify(args.title),
  File "/home/gmg/mediagoblin/mediagoblin/gmg_commands/addmedia.py", line 88, in maybe_unicodeify
    return unicode(some_string)
UnicodeDecodeError: 'ascii' codec can't decode byte 0xc3 in position 5: ordinal not in range(128)

The cause of this error is in the maybe_unicodify method here. Python 2 defaults to decoding strings to Unicode as ASCII - simply adding "utf8" as the second argument will solve this issue.

Change History (6)

comment:1 by Matt Molyneaux, 9 years ago

Cc: berkerpeksag added

comment:2 by berkerpeksag, 9 years ago

Status: newreview

Thanks for the report! This was partly fixed in the Python 3 branch. Here is a more complete fix:

https://gitorious.org/mediagoblin/berkerpeksag-mediagoblin/commits/5ab57277f453afe05ccaf1825eb83e5e6871c9df

The branch name is "1034".

I think we should add tests for GMG commands :)

comment:3 by Matt Molyneaux, 9 years ago

Looks good to me. Thanks for the quick response!

comment:4 by Matt Molyneaux, 9 years ago

Resolution: fixed
Status: reviewclosed

I've tested this on Py2 and it works as advertised, I was unable to get it working on Py3 - master seems to be broken.

As such, I've pushed to master anyway.

comment:5 by berkerpeksag, 9 years ago

Thanks! Is there an issue related to master breakage? I've tested this on Python 3 in my dev environment, by the way.

comment:6 by ayleph, 9 years ago

Is this similar to outstanding issue #1047?

Note: See TracTickets for help on using tickets.