Merge pull request #1541 from cakemanny/fix-number-route-accepting-invalid-float
stop number route accepting excess '.'s
This commit is contained in:
commit
94a1720e04
|
@ -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": (
|
||||
|
|
|
@ -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):
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue
Block a user