UltiSnips crashed while trying to use non-ASCII UTF-8 character in snippet (feature request?)

Bug #908491 reported by Zoran Plesivcak
2
Affects Status Importance Assigned to Milestone
UltiSnips
Fix Released
Critical
Unassigned

Bug Description

I tried to define some snippets with non-english characters, I tried for example Croatian characters "č", "ć" etc. When I tried to use those snippets during expansion of the trigger I immediately got stack-trace and notification that error has occurred.

Here's the stack trace:

> Following is the full stack trace:
> Traceback (most recent call last):
> File "/home/zoran/Dropbox/config/vim/vim/ultisnips_rep/plugin/UltiSnips/__init__.py", line 41, in wrapper
> return f(*args, **kwds)
> File "/home/zoran/Dropbox/config/vim/vim/ultisnips_rep/plugin/UltiSnips/__init__.py", line 677, in list_snippets
> snippet = self._ask_snippets(snippets)
> File "/home/zoran/Dropbox/config/vim/vim/ultisnips_rep/plugin/UltiSnips/__init__.py", line 985, in _ask_snippets
> rv = vim.eval("inputlist(%s)" % vim_string(display))
> File "/home/zoran/Dropbox/config/vim/vim/ultisnips_rep/plugin/UltiSnips/Util.py", line 20, in vim_string
> return conv(inp)
> File "/home/zoran/Dropbox/config/vim/vim/ultisnips_rep/plugin/UltiSnips/Util.py", line 13, in conv
> return u'[' + u",".join([conv(o) for o in obj]) + u']'
> File "/home/zoran/Dropbox/config/vim/vim/ultisnips_rep/plugin/UltiSnips/Util.py", line 19, in conv
> return u'"%s"' % str(obj).replace(u'"', u'\\"')
> UnicodeDecodeError: 'ascii' codec can't decode byte 0xc4 in position 18: ordinal not in range(128)

Ok, I see now that UltiSnips use 'ascii' codec and since above mentioned characters are not in ascii-set they are not decoded. So this should probably be expected behavior of UltiSnips and not strictly a bug; nevertheless I would like to file this as a feature-request if I may. :) Great job with plugin, kicks ass!

Related branches

Revision history for this message
SirVer (sirver) wrote :

Hi and thanks for the bug report. The handling of unicode is generally not easy and it is even more complicated in our case as there is no documentation which encoding vim.eval expects of its strings. After your bug report, I improved upon the situation by converting more explicitily between unicode and utf-8 encoded strings in UltiSnips - this results that german umlauts work for me now in my snippets. This should help you as well.

Unfortunately, the explicit conversion to and from utf-8 might make trouble if the snippet definition files are not encoded in utf-8 or if some vim version expects another encoding for vim.eval - I do not know how to fix this properly for the moment, therefore this 80% must do.

The fix is in r324 in trunk; it would be cool if you could test it and report back.

Changed in ultisnips:
status: New → Confirmed
importance: Undecided → Critical
status: Confirmed → Fix Committed
Revision history for this message
Zoran Plesivcak (zplesivcak-deactivatedaccount) wrote :

Hello, I've tested it and it works great! Test was for croatian characters with snippet files in UTF-8. Thank you very much! Props!

Revision history for this message
SirVer (sirver) wrote :

Release in 1.6.

Changed in ultisnips:
status: Fix Committed → Fix Released
milestone: none → 1.6
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.