Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit f1fd080

Browse files
committed
Minor improvement
1 parent cfe9fb4 commit f1fd080

2 files changed

Lines changed: 24 additions & 4 deletions

File tree

lib/core/convert.py

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,8 @@ def decodeBase64(value, binary=True, encoding=None):
198198
True
199199
>>> decodeBase64("MTIz", binary=False)
200200
'123'
201+
>>> decodeBase64("A-B_CD") == decodeBase64("A+B/CD")
202+
True
201203
>>> decodeBase64(b"MTIzNA") == b"1234"
202204
True
203205
>>> decodeBase64("MTIzNA") == b"1234"
@@ -206,29 +208,44 @@ def decodeBase64(value, binary=True, encoding=None):
206208
True
207209
"""
208210

211+
if value is None:
212+
return None
213+
209214
padding = b'=' if isinstance(value, bytes) else '='
210215

211216
# Reference: https://stackoverflow.com/a/49459036
212217
if not value.endswith(padding):
213218
value += 3 * padding
214219

220+
# Reference: https://en.wikipedia.org/wiki/Base64#URL_applications
221+
# Reference: https://perldoc.perl.org/MIME/Base64.html
222+
if isinstance(value, bytes):
223+
value = value.replace(b'-', b'+').replace(b'_', b'/')
224+
else:
225+
value = value.replace('-', '+').replace('_', '/')
226+
215227
retVal = base64.b64decode(value)
216228

217229
if not binary:
218230
retVal = getText(retVal, encoding)
219231

220232
return retVal
221233

222-
def encodeBase64(value, binary=True, encoding=None):
234+
def encodeBase64(value, binary=True, encoding=None, padding=True):
223235
"""
224236
Returns a decoded representation of provided Base64 value
225237
226238
>>> encodeBase64(b"123") == b"MTIz"
227239
True
228-
>>> encodeBase64(u"123", binary=False)
229-
'MTIz'
240+
>>> encodeBase64(u"1234", binary=False)
241+
'MTIzNA=='
242+
>>> encodeBase64(u"1234", binary=False, padding=False)
243+
'MTIzNA'
230244
"""
231245

246+
if value is None:
247+
return None
248+
232249
if isinstance(value, six.text_type):
233250
value = value.encode(encoding or UNICODE_ENCODING)
234251

@@ -237,6 +254,9 @@ def encodeBase64(value, binary=True, encoding=None):
237254
if not binary:
238255
retVal = getText(retVal, encoding)
239256

257+
if not padding:
258+
retVal = retVal.rstrip(b'=' if isinstance(retVal, bytes) else '=')
259+
240260
return retVal
241261

242262
def getBytes(value, encoding=None, errors="strict", unsafe=True):

lib/core/settings.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
from thirdparty.six import unichr as _unichr
1919

2020
# sqlmap version (<major>.<minor>.<month>.<monthly commit>)
21-
VERSION = "1.4.8.5"
21+
VERSION = "1.4.8.6"
2222
TYPE = "dev" if VERSION.count('.') > 2 and VERSION.split('.')[-1] != '0' else "stable"
2323
TYPE_COLORS = {"dev": 33, "stable": 90, "pip": 34}
2424
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)