def test_ch_unquote(): eq_(cookies._unquote(b'"hello world'), b'"hello world') eq_(cookies._unquote(b'hello world'), b'hello world') eq_(cookies._unquote(b'"hello world"'), b'hello world') # Spaces are not valid in cookies, we support getting them, but won't support sending them assert_raises(ValueError, cookies._value_quote, b'hello world') # quotation mark escaped w/ backslash is unquoted correctly (support # pre webob 1.3 cookies) eq_(cookies._unquote(b'"\\""'), b'"') # we also are able to unquote the newer \\042 serialization of quotation # mark eq_(cookies._unquote(b'"\\042"'), b'"') # New cookies can not contain quotes. assert_raises(ValueError, cookies._value_quote, b'"') # backslash escaped w/ backslash is unquoted correctly (support # pre webob 1.3 cookies) eq_(cookies._unquote(b'"\\\\"'), b'\\') # we also are able to unquote the newer \\134 serialization of backslash eq_(cookies._unquote(b'"\\134"'), b'\\') # Cookies may not contain a backslash assert_raises(ValueError, cookies._value_quote, b'\\') # misc byte escaped as octal eq_(cookies._unquote(b'"\\377"'), b'\xff') assert_raises(ValueError, cookies._value_quote, b'\xff') # combination eq_(cookies._unquote(b'"a\\"\\377"'), b'a"\xff') assert_raises(ValueError, cookies._value_quote, b'a"\xff')
def test_ch_unquote(): eq_(cookies._unquote(b'"hello world'), b'"hello world') eq_(cookies._unquote(b'hello world'), b'hello world') eq_(cookies._unquote(b'"hello world"'), b'hello world') eq_(cookies._value_quote(b'hello world'), b'"hello world"') # quotation mark escaped w/ backslash is unquoted correctly (support # pre webob 1.3 cookies) eq_(cookies._unquote(b'"\\""'), b'"') # we also are able to unquote the newer \\042 serialization of quotation # mark eq_(cookies._unquote(b'"\\042"'), b'"') # but when we generate a new cookie, quote using normal octal quoting # rules eq_(cookies._value_quote(b'"'), b'"\\042"') # backslash escaped w/ backslash is unquoted correctly (support # pre webob 1.3 cookies) eq_(cookies._unquote(b'"\\\\"'), b'\\') # we also are able to unquote the newer \\134 serialization of backslash eq_(cookies._unquote(b'"\\134"'), b'\\') # but when we generate a new cookie, quote using normal octal quoting # rules eq_(cookies._value_quote(b'\\'), b'"\\134"') # misc byte escaped as octal eq_(cookies._unquote(b'"\\377"'), b'\xff') eq_(cookies._value_quote(b'\xff'), b'"\\377"') # combination eq_(cookies._unquote(b'"a\\"\\377"'), b'a"\xff') eq_(cookies._value_quote(b'a"\xff'), b'"a\\042\\377"')
def test_ch_unquote(): eq_(cookies._unquote(u'"hello world'), u'"hello world') eq_(cookies._unquote(u'hello world'), u'hello world') for unq, q in [ ('hello world', '"hello world"'), # quotation mark is escaped w/ backslash ('"', r'"\""'), # misc byte escaped as octal ('\xff', r'"\377"'), # combination ('a"\xff', r'"a\"\377"'), ]: eq_(cookies._unquote(q), unq) eq_(cookies._quote(unq), q)
def extract_cookie_value(response_cookies, cookie_name): """ Making sure cookie unescaped from double quotes when extracting from test response using Webob approach of cookie parsing. """ oscar_open_basket_cookie = bytes_(response_cookies[cookie_name]) oscar_open_basket_cookie = _unquote(oscar_open_basket_cookie) return oscar_open_basket_cookie.decode('utf-8')
def test_ch_unquote(): assert cookies._unquote(b'"hello world') == b'"hello world' assert cookies._unquote(b'hello world') == b'hello world' assert cookies._unquote(b'"hello world"') == b'hello world' # Spaces are not valid in cookies, we support getting them, but won't # support sending them with pytest.raises(ValueError): cookies._value_quote(b'hello world') # quotation mark escaped w/ backslash is unquoted correctly (support # pre webob 1.3 cookies) assert cookies._unquote(b'"\\""') == b'"' # we also are able to unquote the newer \\042 serialization of quotation # mark assert cookies._unquote(b'"\\042"') == b'"' # New cookies can not contain quotes. with pytest.raises(ValueError): cookies._value_quote(b'"') # backslash escaped w/ backslash is unquoted correctly (support # pre webob 1.3 cookies) assert cookies._unquote(b'"\\\\"') == b'\\' # we also are able to unquote the newer \\134 serialization of backslash assert cookies._unquote(b'"\\134"') == b'\\' # Cookies may not contain a backslash with pytest.raises(ValueError): cookies._value_quote(b'\\') # misc byte escaped as octal assert cookies._unquote(b'"\\377"') == b'\xff' with pytest.raises(ValueError): cookies._value_quote(b'\xff') # combination assert cookies._unquote(b'"a\\"\\377"') == b'a"\xff' with pytest.raises(ValueError): cookies._value_quote(b'a"\xff')
def test_ch_unquote(): eq_(cookies._unquote(b'"hello world'), b'"hello world') eq_(cookies._unquote(b'hello world'), b'hello world') eq_(cookies._unquote(b'"hello world"'), b'hello world') eq_(cookies._quote(b'hello world'), b'"hello world"') # quotation mark is escaped w/ backslash eq_(cookies._unquote(b'"\\""'), b'"') eq_(cookies._quote(b'"'), b'"\\""') # misc byte escaped as octal eq_(cookies._unquote(b'"\\377"'), b'\xff') eq_(cookies._quote(b'\xff'), b'"\\377"') # combination eq_(cookies._unquote(b'"a\\"\\377"'), b'a"\xff') eq_(cookies._quote(b'a"\xff'), b'"a\\"\\377"')