stop number route accepting excess '.'s
We stop getting: ValueError: could not convert string to float: '12.34.56' when passing 12.34.56 as a number route parameter argument. By accepting ".12" and "12.", this is a non-breaking change. All valid floats described by [0-9\.]+ are still accepted, just invalid ones are now rejected.
This commit is contained in:
parent
566940e052
commit
b2e82685b4
|
@ -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):
|
||||
|
|
Loading…
Reference in New Issue
Block a user