Fix critical exception if srcset value ends with a comma

Log a debug message as this is a minor syntax problem, won't stop
LinkChecker parsing strings up to the comma.
This commit is contained in:
Chris Mayo 2020-08-07 20:04:23 +01:00
parent a977e4d712
commit 7ba4053710

View file

@ -201,8 +201,17 @@ class LinkFinder:
self.found_url(url, name, base, lineno, column)
elif attr == 'srcset':
for img_candidate in value.split(','):
url = img_candidate.split()[0]
self.found_url(url, name, base, lineno, column)
try:
url = img_candidate.split()[0]
except IndexError:
log.debug(
LOG_CHECK,
_("trailing comma in line: "
"%(line)s srcset attribute: %(value)s")
% {"line": lineno, "value": value}
)
else:
self.found_url(url, name, base, lineno, column)
else:
self.found_url(value, name, base, lineno, column)