Skip to content

Commit

Permalink
Fix file encoding exception (#347)
Browse files Browse the repository at this point in the history
This commit opens .tags files with utf-8 encoding to avoid file encoding
exceptions such as the following, which was raised while looking up symbols
in linux kernel sources.

```
loading symbols from file
Traceback (most recent call last):
  File "<ST>\Lib\python38\sublime_plugin.py", line 1697, in run_
    return self.run(edit, **args)
  File "<ST>\Data\Packages\CTags\plugins\cmds.py", line 587, in command
    result = func(self, self.view, args, tags_file)
  File "<ST>\Data\Packages\CTags\plugins\cmds.py", line 789, in run
    tags = get_tags()
  File "<ST>\Data\Packages\CTags\plugins\cmds.py", line 778, in get_tags
    return tagfile.get_tags_dict(
  File "<ST>\Data\Packages\CTags\plugins\ctags.py", line 567, in get_tags_dict
    filters = kw.get('filters', [])
  File "<ST>\Data\Packages\CTags\plugins\ctags.py", line 86, in parse_tag_lines
    for line in lines:
  File "<ST>\Data\Packages\CTags\plugins\ctags.py", line 518, in search
    while self.mapped.tell() < self.mapped.size():
  File "./python3.8/codecs.py", line 714, in __next__
  File "./python3.8/codecs.py", line 645, in __next__
  File "./python3.8/codecs.py", line 558, in readline
  File "./python3.8/codecs.py", line 504, in read
UnicodeDecodeError: 'ascii' codec can't decode byte 0xc2 in position 135: ordinal not in range(128)
```

.tags files are stored using utf-8 and thus must be opened with that encoding.
  • Loading branch information
deathaxe committed Jan 6, 2024
1 parent 153ab87 commit 9468e67
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion ctags.py
Original file line number Diff line number Diff line change
Expand Up @@ -476,7 +476,7 @@ def open(self):
"""
Open file.
"""
self.file_o = codecs.open(self.path, 'r+b', encoding='ascii')
self.file_o = codecs.open(self.path, 'r+b', encoding='utf-8')
self.mapped = mmap.mmap(self.file_o.fileno(), 0,
access=mmap.ACCESS_READ)

Expand Down

0 comments on commit 9468e67

Please sign in to comment.