From 8abb26acd8a9e1521eccaf4bdd5b893932a5b0f4 Mon Sep 17 00:00:00 2001 From: Deepak singh Date: Thu, 2 Apr 2026 08:03:40 +0000 Subject: [PATCH] fix: replace custom HTML escape table with stdlib html.escape() (closes #48) --- docker_scanner.py | 12 ++++-------- report_generator.py | 12 ++++-------- 2 files changed, 8 insertions(+), 16 deletions(-) diff --git a/docker_scanner.py b/docker_scanner.py index cb9fdf3..6dca10b 100644 --- a/docker_scanner.py +++ b/docker_scanner.py @@ -4,6 +4,7 @@ import csv import pandas as pd import logging +import html from typing import List, Tuple, Dict, Optional from datetime import datetime from fpdf import FPDF @@ -1240,15 +1241,10 @@ def _escape_html(self, text: str) -> str: if not text: return "" - html_escape_table = { - "&": "&", - '"': """, - "'": "'", - ">": ">", - "<": "<", - } + if not isinstance(text, str): + text = str(text) - return "".join(html_escape_table.get(c, c) for c in str(text)) + return html.escape(text, quote=True) def main(): """Main function to run the security scanner.""" diff --git a/report_generator.py b/report_generator.py index 3b183de..08918d1 100644 --- a/report_generator.py +++ b/report_generator.py @@ -16,6 +16,7 @@ import csv import re import logging +import html from typing import Dict, List, Optional from datetime import datetime from fpdf import FPDF @@ -467,15 +468,10 @@ def _escape_html(self, text: str) -> str: if not text: return "" - html_escape_table = { - "&": "&", - '"': """, - "'": "'", - ">": ">", - "<": "<", - } + if not isinstance(text, str): + text = str(text) - return "".join(html_escape_table.get(c, c) for c in str(text)) + return html.escape(text, quote=True) def _count_by_severity(self, vulnerabilities: List[Dict]) -> Dict[str, int]: """