Skip to content

Commit bf8b995

Browse files
committed
Fixes #6170
1 parent 8476cf4 commit bf8b995

3 files changed

Lines changed: 17 additions & 1 deletion

File tree

‎lib/core/convert.py‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,9 @@ def _serializeEncode(value):
125125
if isinstance(value, decimal.Decimal):
126126
return {_SERIALIZE_TAG: "dec", "v": getUnicode(value)}
127127

128+
if isinstance(value, (datetime.datetime, datetime.time)) and value.tzinfo is not None:
129+
return getUnicode(value) # Note: time zone aware value (e.g. from '-d' connector) kept as displayed, as an arbitrary tzinfo can't be rebuilt
130+
128131
if isinstance(value, datetime.datetime):
129132
return {_SERIALIZE_TAG: "dt", "v": [value.year, value.month, value.day, value.hour, value.minute, value.second, value.microsecond]}
130133

‎lib/core/settings.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
from thirdparty import six
2020

2121
# sqlmap version (<major>.<minor>.<month>.<monthly commit>)
22-
VERSION = "1.10.11.3"
22+
VERSION = "1.10.11.4"
2323
TYPE = "dev" if VERSION.count('.') > 2 and VERSION.split('.')[-1] != '0' else "stable"
2424
TYPE_COLORS = {"dev": 33, "stable": 90, "pip": 34}
2525
VERSION_STRING = "sqlmap/%s#%s" % ('.'.join(VERSION.split('.')[:-1]) if VERSION.count('.') > 2 and VERSION.split('.')[-1] == '0' else VERSION, TYPE)

‎tests/test_serialize.py‎

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -259,6 +259,19 @@ def test_datetime_family(self):
259259
self.assertEqual(restored, value)
260260
self.assertIs(type(restored), type(value))
261261

262+
def test_timezone_aware_kept_as_displayed(self):
263+
# Note: a resumed '-d' session used to drop the offset (e.g. '+05:30'), as only naive fields got stored
264+
class _Offset(datetime.tzinfo):
265+
def utcoffset(self, dt):
266+
return datetime.timedelta(hours=5, minutes=30)
267+
268+
def dst(self, dt):
269+
return datetime.timedelta(0)
270+
271+
for value in (datetime.datetime(2024, 1, 2, 3, 4, 0, tzinfo=_Offset()), datetime.time(3, 4, 0, tzinfo=_Offset())):
272+
self.assertEqual(rt(value), getUnicode(value))
273+
self.assertTrue(rt(value).endswith("+05:30"))
274+
262275

263276
class TestRealSessionObjects(unittest.TestCase):
264277
# the exact shapes written with serialize=True across the codebase

0 commit comments

Comments
 (0)