#!/usr/bin/env python """ Copyright (c) 2006-2026 sqlmap developers (https://sqlmap.org) See the file 'LICENSE' for copying permission Response charset / meta detection and parameter parsing. checkCharEncoding canonicalizes the encoding sqlmap will decode a page with; META_CHARSET_REGEX / HTML_TITLE_REGEX / META_REFRESH_REGEX pull structural hints out of the body; paramToDict splits the parameters sqlmap will inject into. These feed decodePage and the comparison engine, so the canonical/None results are pinned here. """ import os import sys import unittest sys.path.insert(0, os.path.dirname(os.path.abspath(__file__))) from _testutils import bootstrap bootstrap() from lib.request.basic import checkCharEncoding from lib.core.common import extractRegexResult, paramToDict from lib.core.enums import PLACE from lib.core.settings import META_CHARSET_REGEX, HTML_TITLE_REGEX, META_REFRESH_REGEX class TestCheckCharEncoding(unittest.TestCase): def test_canonical_known(self): for enc in ("utf-8", "windows-1252", "iso-8859-1", "ascii", "latin1"): self.assertEqual(checkCharEncoding(enc, False), enc, msg="checkCharEncoding(%r)" % enc) def test_normalizes_aliases(self): self.assertEqual(checkCharEncoding("UTF8", False), "utf8") self.assertEqual(checkCharEncoding("us-ascii", False), "ascii") def test_unknown_is_none(self): self.assertIsNone(checkCharEncoding("boguscharset123", False)) def test_none_is_none(self): self.assertIsNone(checkCharEncoding(None, False)) class TestBodyHints(unittest.TestCase): def test_meta_charset(self): self.assertEqual(extractRegexResult(META_CHARSET_REGEX, '
'), "utf-8") def test_title(self): self.assertEqual(extractRegexResult(HTML_TITLE_REGEX, "