Skip to content

Commit 09fadc4

Browse files
committed
Minor improvement of stdoutEncode
1 parent ba05bb6 commit 09fadc4

File tree

3 files changed

+27
-28
lines changed

3 files changed

+27
-28
lines changed

data/txt/sha256sums.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ ac44a343947162532dbf17bd1f9ab424f8008f677367c5ad3f9f7b715a679818 lib/core/agent
170170
86a9cb82c7e7beb4730264dae20bf3b7cd87c0dcaee587367362cf319f7bb079 lib/core/bigarray.py
171171
f6062e324fdeaacf9df0a289fc3f12f755143e3876a70cb65b38aa2e690f73c1 lib/core/common.py
172172
11c748cc96ea2bc507bc6c1930a17fe4bc6fdd2dd2a80430df971cb21428eb00 lib/core/compat.py
173-
c6e54bfb1e3bc116ced8d525978ba3f4a10a59b99bc48d895b73359df0682d9b lib/core/convert.py
173+
e5eae3c41fbe525326a14fa240882ba7e1083e0fc0561f15c9ae41a4592d3f53 lib/core/convert.py
174174
ae500647c4074681749735a4f3b17b7eca44868dd3f39f9cab0a575888ba04a1 lib/core/data.py
175175
b22decc8389c94a13f1adf07eb343cf3b2aae3fb3909fd4107e24bbede7c7deb lib/core/datatype.py
176176
253309dc355ae27cd275e7de5a068e7e22feba603c4fe3429e2b69f8a51c0d13 lib/core/decorators.py
@@ -190,7 +190,7 @@ c4bfb493a03caf84dd362aec7c248097841de804b7413d0e1ecb8a90c8550bc0 lib/core/readl
190190
d1bd70c1a55858495c727fbec91e30af267459c8f64d50fabf9e4ee2c007e920 lib/core/replication.py
191191
1d0f80b0193ac5204527bfab4bde1a7aee0f693fd008e86b4b29f606d1ef94f3 lib/core/revision.py
192192
d2eb8e4b05ac93551272b3d4abfaf5b9f2d3ac92499a7704c16ed0b4f200db38 lib/core/session.py
193-
72affdfd108cd7c4c10b54389917b018731e592a5f8e087c38e14620bea551d0 lib/core/settings.py
193+
f869523fb2f64f4cb415ede7dda998b903dfd885c6a65b860e4f572497675181 lib/core/settings.py
194194
1c5eab9494eb969bc9ce118a2ea6954690c6851cbe54c18373c723b99734bf09 lib/core/shell.py
195195
4eea6dcf023e41e3c64b210cb5c2efc7ca893b727f5e49d9c924f076bb224053 lib/core/subprocessng.py
196196
cdd352e1331c6b535e780f6edea79465cb55af53aa2114dcea0e8bf382e56d1a lib/core/target.py

lib/core/convert.py

Lines changed: 24 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -405,10 +405,13 @@ def getText(value, encoding=None):
405405

406406
def stdoutEncode(value):
407407
"""
408-
Returns binary representation of a given Unicode value safe for writing to stdout
408+
Returns textual representation of a given value safe for writing to stdout
409+
>>> stdoutEncode(b"foobar")
410+
'foobar'
409411
"""
410412

411-
value = value or ""
413+
if value is None:
414+
value = ""
412415

413416
if IS_WIN and IS_TTY and kb.get("codePage", -1) is None:
414417
output = shellExec("chcp")
@@ -418,36 +421,32 @@ def stdoutEncode(value):
418421
try:
419422
candidate = "cp%s" % match.group(1)
420423
codecs.lookup(candidate)
421-
except LookupError:
422-
pass
423-
else:
424424
kb.codePage = candidate
425+
except (LookupError, TypeError):
426+
pass
425427

426428
kb.codePage = kb.codePage or ""
427429

428-
if isinstance(value, six.text_type):
429-
encoding = kb.get("codePage") or getattr(sys.stdout, "encoding", None) or UNICODE_ENCODING
430+
encoding = kb.get("codePage") or getattr(sys.stdout, "encoding", None) or UNICODE_ENCODING
430431

431-
while True:
432-
try:
433-
retVal = value.encode(encoding)
434-
break
435-
except UnicodeEncodeError as ex:
436-
value = value[:ex.start] + "?" * (ex.end - ex.start) + value[ex.end:]
437-
438-
warnMsg = "cannot properly display (some) Unicode characters "
439-
warnMsg += "inside your terminal ('%s') environment. All " % encoding
440-
warnMsg += "unhandled occurrences will result in "
441-
warnMsg += "replacement with '?' character. Please, find "
442-
warnMsg += "proper character representation inside "
443-
warnMsg += "corresponding output files"
444-
singleTimeWarnMessage(warnMsg)
445-
446-
if six.PY3:
447-
retVal = getUnicode(retVal, encoding)
432+
if six.PY3:
433+
if isinstance(value, (bytes, bytearray)):
434+
value = getUnicode(value, encoding)
435+
elif not isinstance(value, str):
436+
value = str(value)
448437

438+
try:
439+
retVal = value.encode(encoding, errors="replace").decode(encoding, errors="replace")
440+
except (LookupError, TypeError):
441+
retVal = value.encode("ascii", errors="replace").decode("ascii", errors="replace")
449442
else:
450-
retVal = value
443+
if isinstance(value, six.text_type):
444+
try:
445+
retVal = value.encode(encoding, errors="replace")
446+
except (LookupError, TypeError):
447+
retVal = value.encode("ascii", errors="replace")
448+
else:
449+
retVal = value
451450

452451
return retVal
453452

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.9.12.53"
22+
VERSION = "1.9.12.54"
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)

0 commit comments

Comments
 (0)