Skip to content

Commit

Permalink
Add: check_encoding -> print line with found char
Browse files Browse the repository at this point in the history
  • Loading branch information
mbrinkhoff committed Feb 28, 2025
1 parent 948ff2b commit 4e3374e
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
4 changes: 2 additions & 2 deletions tests/plugins/test_encoding.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,11 +70,11 @@ def test_some_invalid_characters(self):
results[0].message,
)
self.assertEqual(
"Found invalid character",
"Found invalid character in line: 1",
results[1].message,
)
self.assertEqual(
"Found invalid character",
"Found invalid character in line: 2",
results[2].message,
)

Expand Down
8 changes: 4 additions & 4 deletions troubadix/plugins/encoding.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
# Only the ASCII and extended ASCII for now... # https://www.ascii-code.com/
# CHAR_SET = r"[^\x00-\xFF]"
# Temporary only check for chars in between 7f-9f, like in the old Feed-QA...
CHAR_SET = r"[\x7F-\x9F]"
INVALID_CHAR_PATTERN = re.compile(r"[\x7F-\x9F]")

ALLOWED_ENCODINGS = ["ascii", "latin_1"]

Expand All @@ -52,10 +52,10 @@ def check_lines(
)

for index, line in enumerate(lines, 1):
encoding = re.search(CHAR_SET, line)
if encoding is not None:
encoding = INVALID_CHAR_PATTERN.search(line)
if encoding:
yield LinterError(
"Found invalid character",
f"Found invalid character in line: {index}",
file=nasl_file,
plugin=self.name,
line=index,
Expand Down

0 comments on commit 4e3374e

Please sign in to comment.