Merge pull request #1541 from cakemanny/fix-number-route-accepting-invalid-float

stop number route accepting excess '.'s
This commit is contained in:
7 2019-03-28 10:42:24 -07:00 committed by GitHub
commit 94a1720e04
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 20 additions and 2 deletions

View File

@ -18,7 +18,7 @@ Parameter = namedtuple("Parameter", ["name", "cast"])
REGEX_TYPES = {
"string": (str, r"[^/]+"),
"int": (int, r"-?\d+"),
"number": (float, r"-?[0-9\\.]+"),
"number": (float, r"-?(?:\d+(?:\.\d*)?|\.\d+)"),
"alpha": (str, r"[A-Za-z]+"),
"path": (str, r"[^/].*?"),
"uuid": (

View File

@ -365,9 +365,18 @@ def test_dynamic_route_number(app):
request, response = app.test_client.get("/weight/1234.56")
assert response.status == 200
request, response = app.test_client.get("/weight/.12")
assert response.status == 200
request, response = app.test_client.get("/weight/12.")
assert response.status == 200
request, response = app.test_client.get("/weight/1234-56")
assert response.status == 404
request, response = app.test_client.get("/weight/12.34.56")
assert response.status == 404
def test_dynamic_route_regex(app):
@app.route("/folder/<folder_id:[A-Za-z0-9]{0,4}>")
@ -672,9 +681,18 @@ def test_dynamic_add_route_number(app):
request, response = app.test_client.get("/weight/1234.56")
assert response.status == 200
request, response = app.test_client.get("/weight/.12")
assert response.status == 200
request, response = app.test_client.get("/weight/12.")
assert response.status == 200
request, response = app.test_client.get("/weight/1234-56")
assert response.status == 404
request, response = app.test_client.get("/weight/12.34.56")
assert response.status == 404
def test_dynamic_add_route_regex(app):
async def handler(request, folder_id):

View File

@ -223,7 +223,7 @@ def test_fails_with_number_message(app):
expected_error = (
'Value "foo" for parameter `some_number` '
"does not match pattern for type `float`: -?[0-9\\\\.]+"
r"does not match pattern for type `float`: -?(?:\d+(?:\.\d*)?|\.\d+)"
)
assert str(e.value) == expected_error