Skip to content

Commit

Permalink
Merge branch 'main' into ranges-off-by-one
Browse files Browse the repository at this point in the history
  • Loading branch information
ahopkins authored Nov 28, 2023
2 parents 31a4064 + d0f7f40 commit be59262
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 7 deletions.
11 changes: 8 additions & 3 deletions sanic/cookies/request.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,12 +73,17 @@ 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:
# Empty value like ;; or a cookie header with no value
continue
name, value = "", name

if COOKIE_NAME_RESERVED_CHARS.search(name): # no cov
continue
Expand Down
6 changes: 3 additions & 3 deletions sanic/models/protocol_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import sys

from asyncio import BaseTransport
from typing import TYPE_CHECKING, Any, AnyStr, Optional
from typing import TYPE_CHECKING, Any, Optional, Union


if TYPE_CHECKING:
Expand All @@ -19,10 +19,10 @@
from typing import Protocol

class HTMLProtocol(Protocol):
def __html__(self) -> AnyStr:
def __html__(self) -> Union[str, bytes]:
...

def _repr_html_(self) -> AnyStr:
def _repr_html_(self) -> Union[str, bytes]:
...

class Range(Protocol):
Expand Down
18 changes: 17 additions & 1 deletion tests/test_cookies.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,28 @@
from sanic import Request, Sanic
from sanic.compat import Header
from sanic.cookies import Cookie, CookieJar
from sanic.cookies.request import CookieRequestParameters
from sanic.cookies.request import CookieRequestParameters, parse_cookie
from sanic.exceptions import ServerError
from sanic.response import text
from sanic.response.convenience import json


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


# ------------------------------------------------------------ #
# GET
# ------------------------------------------------------------ #
Expand Down
3 changes: 3 additions & 0 deletions tests/test_graceful_shutdown.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import asyncio
import logging

import pytest

from pytest import LogCaptureFixture

from sanic.response import empty
Expand All @@ -9,6 +11,7 @@
PORT = 42101


@pytest.mark.xfail(reason="This test runs fine locally, but fails on CI")
def test_no_exceptions_when_cancel_pending_request(
app, caplog: LogCaptureFixture
):
Expand Down

0 comments on commit be59262

Please sign in to comment.