linter: Fix UnicodeError when parsing comments
And add tests when reading non-ASCII strings and comments (both from Python strings and from files). Fixes: #10
This commit is contained in:
@@ -71,7 +71,10 @@ def get_costemic_problems(buffer, conf):
|
||||
self.all_rules = set([r.ID for r in rules])
|
||||
|
||||
def process_comment(self, comment):
|
||||
comment = repr(comment)
|
||||
try:
|
||||
comment = str(comment)
|
||||
except UnicodeError:
|
||||
return # this certainly wasn't a yamllint directive comment
|
||||
|
||||
if re.match(r'^# yamllint disable( rule:\S+)*\s*$', comment):
|
||||
rules = [item[5:] for item in comment[18:].split(' ')][1:]
|
||||
@@ -95,7 +98,10 @@ def get_costemic_problems(buffer, conf):
|
||||
|
||||
class DisableLineDirective(DisableDirective):
|
||||
def process_comment(self, comment):
|
||||
comment = repr(comment)
|
||||
try:
|
||||
comment = str(comment)
|
||||
except UnicodeError:
|
||||
return # this certainly wasn't a yamllint directive comment
|
||||
|
||||
if re.match(r'^# yamllint disable-line( rule:\S+)*\s*$', comment):
|
||||
rules = [item[5:] for item in comment[23:].split(' ')][1:]
|
||||
|
||||
@@ -49,7 +49,7 @@ class Comment(object):
|
||||
self.token_after = token_after
|
||||
self.comment_before = comment_before
|
||||
|
||||
def __repr__(self):
|
||||
def __str__(self):
|
||||
end = self.buffer.find('\n', self.pointer)
|
||||
if end == -1:
|
||||
end = self.buffer.find('\0', self.pointer)
|
||||
|
||||
Reference in New Issue
Block a user