Compare commits
3 Commits
guide
...
bare-cooki
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
a202435283 | ||
|
|
6d433af406 | ||
|
|
a5a9658896 |
@@ -22,7 +22,6 @@ span.linenos.special { color: #000000; background-color: #ffffc0; padding-left:
|
||||
.cs { color: #a2a2a2; font-style: italic } /* Comment.Special */
|
||||
.gd { color: #777777 } /* Generic.Deleted */
|
||||
.ge { color: #777777 } /* Generic.Emph */
|
||||
.ges { color: #777777 } /* Generic.EmphStrong */
|
||||
.gr { color: #777777 } /* Generic.Error */
|
||||
.gh { color: #777777 } /* Generic.Heading */
|
||||
.gi { color: #777777 } /* Generic.Inserted */
|
||||
|
||||
@@ -1,8 +1,3 @@
|
||||
sanic>=23.6.*
|
||||
sanic-ext>=23.6.*
|
||||
msgspec
|
||||
python-frontmatter
|
||||
pygments
|
||||
docstring-parser
|
||||
libsass
|
||||
mistune
|
||||
|
||||
@@ -1,11 +1,3 @@
|
||||
"""Sanic User Guide
|
||||
|
||||
https://sanic.dev
|
||||
|
||||
Built using the SHH stack:
|
||||
- Sanic
|
||||
- html5tagger
|
||||
- HTMX"""
|
||||
from pathlib import Path
|
||||
|
||||
from webapp.worker.factory import create_app
|
||||
|
||||
@@ -73,12 +73,16 @@ def parse_cookie(raw: str) -> Dict[str, List[str]]:
|
||||
cookies: Dict[str, List[str]] = {}
|
||||
|
||||
for token in raw.split(";"):
|
||||
name, __, value = token.partition("=")
|
||||
name, sep, value = token.partition("=")
|
||||
name = name.strip()
|
||||
value = value.strip()
|
||||
|
||||
if not name:
|
||||
continue
|
||||
# Support cookies =value or plain value with no name
|
||||
# https://github.com/httpwg/http-extensions/issues/159
|
||||
if not sep:
|
||||
if not name:
|
||||
continue # Empty value like ;; or a cookie header with no value
|
||||
name, value = "", name
|
||||
|
||||
if COOKIE_NAME_RESERVED_CHARS.search(name): # no cov
|
||||
continue
|
||||
|
||||
@@ -11,6 +11,20 @@ from sanic.cookies.request import CookieRequestParameters
|
||||
from sanic.exceptions import ServerError
|
||||
from sanic.response import text
|
||||
from sanic.response.convenience import json
|
||||
from sanic.cookies.request import parse_cookie
|
||||
|
||||
def test_request_cookies():
|
||||
cdict = parse_cookie("foo=one; foo=two; abc = xyz;;bare;=bare2")
|
||||
assert cdict == {
|
||||
"foo": ["one", "two"],
|
||||
"abc": ["xyz"],
|
||||
"": ["bare", "bare2"],
|
||||
}
|
||||
c = CookieRequestParameters(cdict)
|
||||
assert c.getlist("foo") == ["one", "two"]
|
||||
assert c.getlist("abc") == ["xyz"]
|
||||
assert c.getlist("") == ["bare", "bare2"]
|
||||
assert c.getlist("bare") == None # [] might be sensible but we got None for now
|
||||
|
||||
|
||||
# ------------------------------------------------------------ #
|
||||
|
||||
@@ -20,6 +20,7 @@ from pytest import LogCaptureFixture
|
||||
|
||||
from sanic import Request, Sanic
|
||||
from sanic.compat import Header
|
||||
from sanic.constants import DEFAULT_HTTP_CONTENT_TYPE
|
||||
from sanic.cookies import CookieJar
|
||||
from sanic.response import (
|
||||
HTTPResponse,
|
||||
@@ -545,7 +546,7 @@ def test_raw_response(app):
|
||||
return raw(b"raw_response")
|
||||
|
||||
request, response = app.test_client.get("/test")
|
||||
assert response.content_type == "application/octet-stream"
|
||||
assert response.content_type == DEFAULT_HTTP_CONTENT_TYPE
|
||||
assert response.body == b"raw_response"
|
||||
|
||||
|
||||
|
||||
@@ -502,7 +502,7 @@ def test_dynamic_route_int(app):
|
||||
|
||||
request, response = app.test_client.get("/folder/12345")
|
||||
assert response.text == "OK"
|
||||
assert type(results[0]) is int
|
||||
assert isinstance(results[0], int)
|
||||
|
||||
request, response = app.test_client.get("/folder/asdf")
|
||||
assert response.status == 404
|
||||
@@ -518,7 +518,7 @@ def test_dynamic_route_number(app):
|
||||
|
||||
request, response = app.test_client.get("/weight/12345")
|
||||
assert response.text == "OK"
|
||||
assert type(results[0]) is float
|
||||
assert isinstance(results[0], float)
|
||||
|
||||
request, response = app.test_client.get("/weight/1234.56")
|
||||
assert response.status == 200
|
||||
@@ -567,7 +567,7 @@ def test_dynamic_route_uuid(app):
|
||||
url = "/quirky/123e4567-e89b-12d3-a456-426655440000"
|
||||
request, response = app.test_client.get(url)
|
||||
assert response.text == "OK"
|
||||
assert type(results[0]) is uuid.UUID
|
||||
assert isinstance(results[0], uuid.UUID)
|
||||
|
||||
generated_uuid = uuid.uuid4()
|
||||
request, response = app.test_client.get(f"/quirky/{generated_uuid}")
|
||||
@@ -861,7 +861,7 @@ def test_dynamic_add_route_int(app):
|
||||
|
||||
request, response = app.test_client.get("/folder/12345")
|
||||
assert response.text == "OK"
|
||||
assert type(results[0]) is int
|
||||
assert isinstance(results[0], int)
|
||||
|
||||
request, response = app.test_client.get("/folder/asdf")
|
||||
assert response.status == 404
|
||||
@@ -878,7 +878,7 @@ def test_dynamic_add_route_number(app):
|
||||
|
||||
request, response = app.test_client.get("/weight/12345")
|
||||
assert response.text == "OK"
|
||||
assert type(results[0]) is float
|
||||
assert isinstance(results[0], float)
|
||||
|
||||
request, response = app.test_client.get("/weight/1234.56")
|
||||
assert response.status == 200
|
||||
|
||||
Reference in New Issue
Block a user