From fdc295a79c5a8a1da381d646b5430ac0e0230a92 Mon Sep 17 00:00:00 2001 From: TheGreatAlgo <37487508+TheGreatAlgo@users.noreply.github.com> Date: Fri, 7 Jul 2023 23:44:52 +0200 Subject: [PATCH] clearer url rule slash error --- CHANGES.rst | 1 + src/werkzeug/routing/rules.py | 3 ++- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/CHANGES.rst b/CHANGES.rst index 88970a666..a749a2129 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -11,6 +11,7 @@ Unreleased - ``_plain_int`` and ``_plain_float`` strip whitespace before type enforcement. :issue:`2734` - Fix empty file streaming when testing. :issue:`2740` +- Clearer error message when URL rule does not start with slash. :pr:`2750` Version 2.3.6 diff --git a/src/werkzeug/routing/rules.py b/src/werkzeug/routing/rules.py index d65dce028..904a02258 100644 --- a/src/werkzeug/routing/rules.py +++ b/src/werkzeug/routing/rules.py @@ -454,7 +454,8 @@ def __init__( websocket: bool = False, ) -> None: if not string.startswith("/"): - raise ValueError("urls must start with a leading slash:", string) + raise ValueError(f"URL rule '{string}' must start with a slash.") + self.rule = string self.is_leaf = not string.endswith("/") self.is_branch = string.endswith("/")