Home > database >  Strange character added when decoding with urllib
Strange character added when decoding with urllib

Time:10-21

I'm trying to parse a query string like this: filename=logo.txt\\x80\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x01x&filename=.hidden.txt

Since it mixes bytes and text, I tried to alter it such that it will produce the desired escaped url output like so:

    extended = 'filename=logo.txt\\x80\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x01x&filename=.hidden.txt'
    fixbytes = bytes(extended, 'utf-8')
    fixbytes = fixbytes.decode("unicode_escape")
    algoext = '?'   urllib.parse.quote(fixbytes, safe='?&=')

This outputs b'filename=logo.txt\\x80\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x01x&filename=.hidden.txt'

filename=logo.txtx&filename=.hidden.txt

?filename=logo.txt€x&filename=.hidden.txt

Where does the

  • Related