Skip to main content

Encoding and decoding arbitrary strings into strings that are safe to put into a URL query param.

Project description

[![Build Status](https://travis-ci.org/ClearcodeHQ/querystringsafe_base64.svg?branch=master)](https://travis-ci.org/ClearcodeHQ/querystringsafe_base64) [![Coverage Status](https://img.shields.io/coveralls/ClearcodeHQ/querystringsafe_base64.svg)](https://coveralls.io/r/ClearcodeHQ/querystringsafe_base64)

# Query string safe Base64

Encoding and decoding arbitrary strings into strings that are safe to put into a URL query param.

## The problem

urlsafe_b64encode and urlsafe_b64decode from base64 are not enough because they leave = chars unquoted:

>>> import base64
>>> base64.urlsafe_b64encode('a')
>>> 'YQ=='

And there are 2 problems with that

  1. = sign gets quoted:

    >>> import urllib
    
    >>> urllib.quote('=')
    '%3D'
    
  2. Some libraries tolerate the = in query string values:

    >>> from urlparse import urlsplit, parse_qs
    
    >>> parse_qs(urlsplit('http://aaa.com/asa?q=AAAA=BBBB=CCCC').query)
    {'q': ['AAAA=BBBB=CCCC']}
    

but the RFC 3986 underspecifies the query string so we cannot rely on = chars being handled by all web applications as it is done by urlparse.

Therefore we consider chars: [‘+’, ‘/’, ‘=’] unsafe and we replace them with [‘-’, ‘_’, ‘.’]. Characters + and / are already handled by urlsafe_* functions from base64 so only = is left for us. The . character has been chosen because it often appears in real world query strings and it is not used by base64.

## The solution

>>> import querystringsafe_base64
>>> querystringsafe_base64.encode('foo-bar')
>>> 'Zm9vLWJhcg..'
>>> querystringsafe_base64.decode('Zm9vLWJhcg..')
>>> 'foo-bar'

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

querystringsafe_base64-0.2.0.tar.gz (4.0 kB view details)

Uploaded Source

Built Distributions

querystringsafe_base64-0.2.0-py3.5.egg (4.4 kB view details)

Uploaded Source

querystringsafe_base64-0.2.0-py3.4.egg (4.4 kB view details)

Uploaded Source

querystringsafe_base64-0.2.0-py3.3.egg (4.4 kB view details)

Uploaded Source

querystringsafe_base64-0.2.0-py2.7.egg (4.3 kB view details)

Uploaded Source

querystringsafe_base64-0.2.0-py2.6.egg (4.3 kB view details)

Uploaded Source

File details

Details for the file querystringsafe_base64-0.2.0.tar.gz.

File metadata

File hashes

Hashes for querystringsafe_base64-0.2.0.tar.gz
Algorithm Hash digest
SHA256 1bf7cae5509a1e4bc17ebf3518aa1e2a21bd6e03a7f82f156eb2d84bdaa7dc58
MD5 3b1dcf9282845b48314a97d405dd2e74
BLAKE2b-256 16d11cf3bdc8eb29dd42d57c3ebaf837c06efbf4e7f7e2226e46b52fbc5e815d

See more details on using hashes here.

File details

Details for the file querystringsafe_base64-0.2.0-py3.5.egg.

File metadata

File hashes

Hashes for querystringsafe_base64-0.2.0-py3.5.egg
Algorithm Hash digest
SHA256 d54e3c7aa7a2e7fbd49ee4bd39595eadad636f56e16b33c14ba2e3a1f928f312
MD5 9647ef7236ebb7edc0169c2d88ef79c0
BLAKE2b-256 681a93c29f3c244fc425737302cc00efc7831765ef0a8e252307aed09c66cb8f

See more details on using hashes here.

File details

Details for the file querystringsafe_base64-0.2.0-py3.4.egg.

File metadata

File hashes

Hashes for querystringsafe_base64-0.2.0-py3.4.egg
Algorithm Hash digest
SHA256 fc15ea4ce494a4585497513ac947095262bdcad3cb304c6c870418d45824a659
MD5 574294575273e1709c012c185c9859ae
BLAKE2b-256 18efe7d1f1b8eeaab4d62960cdb397127e87bd3411b875e617deef3a3b05a26e

See more details on using hashes here.

File details

Details for the file querystringsafe_base64-0.2.0-py3.3.egg.

File metadata

File hashes

Hashes for querystringsafe_base64-0.2.0-py3.3.egg
Algorithm Hash digest
SHA256 977ae9b93f64413e83f84763cac8046e0d17d0e0a599842cb0be80c573b85cb2
MD5 798c4c6cbfa147902805f9cc20e00b49
BLAKE2b-256 6b9b2a0fc0910daeb0da91643fcb54c1a98427f39922ed78bb2bdac02773fc74

See more details on using hashes here.

File details

Details for the file querystringsafe_base64-0.2.0-py2.7.egg.

File metadata

File hashes

Hashes for querystringsafe_base64-0.2.0-py2.7.egg
Algorithm Hash digest
SHA256 682df1043abd816be9805cc06cb2da67add4311735af5de925f81dd2cfea82da
MD5 d2ca020d489726d387fb5ff581d04728
BLAKE2b-256 d5d4bc270447b1e6df59a8c1c9000cbc80be08707f08562a3121dcaf17e9a9c3

See more details on using hashes here.

File details

Details for the file querystringsafe_base64-0.2.0-py2.6.egg.

File metadata

File hashes

Hashes for querystringsafe_base64-0.2.0-py2.6.egg
Algorithm Hash digest
SHA256 1064ad8d8bf5a88501e9f895b6560d1c45949645557fd6020abec8bbbe9462ec
MD5 8e20b8e014c701df0f57152efbd20737
BLAKE2b-256 b061a1554f89d12dc074dc4e182cbc6c003dbd350988f605871eece7eb62fd68

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page