Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/core/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -2444,7 +2444,7 @@ def isHexEncodedString(subject):
False
"""

return re.match(r"\A[0-9a-fA-Fx]+\Z", subject) is not None
return re.match(r"\A(?:0[xX])?[0-9a-fA-F]+\Z", subject) is not None

@cachedmethod
def getConsoleWidth(default=80):
Expand Down
36 changes: 36 additions & 0 deletions tests/test_hex_prefix_regression.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#!/usr/bin/env python

"""
Copyright (c) 2006-2026 sqlmap developers (https://sqlmap.org)
See the file 'LICENSE' for copying permission
"""

import os
import sys
import unittest

sys.path.insert(0, os.path.dirname(os.path.abspath(__file__)))
from _testutils import bootstrap

bootstrap()

from lib.core.common import isHexEncodedString


class TestHexPrefixDetection(unittest.TestCase):
def test_bare_x_is_not_a_hex_prefix(self):
self.assertFalse(isHexEncodedString("x4142"))
self.assertFalse(isHexEncodedString("4142x"))

def test_prefix_requires_digits(self):
self.assertFalse(isHexEncodedString("0x"))
self.assertFalse(isHexEncodedString("0X"))

def test_valid_hex_is_still_detected(self):
self.assertTrue(isHexEncodedString("4142"))
self.assertTrue(isHexEncodedString("0x4142"))
self.assertTrue(isHexEncodedString("0X4142"))


if __name__ == "__main__":
unittest.main()