From 4e3374ec2daa83847493cc31ced7350d65f710ef Mon Sep 17 00:00:00 2001 From: mbrinkhoff Date: Thu, 27 Feb 2025 19:59:17 +0100 Subject: [PATCH] Add: check_encoding -> print line with found char --- tests/plugins/test_encoding.py | 4 ++-- troubadix/plugins/encoding.py | 8 ++++---- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/tests/plugins/test_encoding.py b/tests/plugins/test_encoding.py index 164c9d24..af7441e6 100644 --- a/tests/plugins/test_encoding.py +++ b/tests/plugins/test_encoding.py @@ -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, ) diff --git a/troubadix/plugins/encoding.py b/troubadix/plugins/encoding.py index 727e5529..5023054f 100644 --- a/troubadix/plugins/encoding.py +++ b/troubadix/plugins/encoding.py @@ -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"] @@ -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,