SublimeText/CTags — Issue #27: CTags "Navigate To Definition" command sometimes raises UnicodeDecodeError
Author: bradlarsen
Created: 2012-02-29 17:52:46+00:00
State: open

On my Mac (OS X 10.7.3), sometimes when I use the Navigate To Definition command, the CTags plugin raises a UnicodeDecodeError:

Traceback (most recent call last):
File "./sublime_plugin.py", line 350, in run_
File "./ctagsplugin.py", line 431, in command
File "./ctagsplugin.py", line 486, in run
File "./ctags.py", line 259, in get_tags_dict
File "./ctags.py", line 60, in parse_tag_lines
File "./ctags.py", line 59, in
File "./ctags.py", line 59, in
File "./ctags.py", line 222, in get
UnicodeDecodeError: 'ascii' codec can't decode byte 0xfe in position 9: ordinal not in range(128)

I can eliminate this problem on my Mac by calling `encode` on the tag variable used on line 222:

```diff
diff --git a/ctags.py b/ctags.py
index 42c032b..f0ff44e 100644
--- a/ctags.py
+++ b/ctags.py
@@ -217,7 +217,7 @@ class TagFile(object):
with open(self.p, 'r+') as fh:
self.fh = mmap.mmap(fh.fileno(), 0)

- for tag in tags:
+ for tag in (t.encode() for t in tags):
b4 = bisect.bisect_left(self, tag)
fh.seek(b4)
```

However, I don't know if this breaks the plugin on other systems, or if this is the proper way to fix this bug. (I find Unicode in Python 2.x a bit mystifying.)