fix: reject trailing newline in tool-name and URI-template varname validation (#3076)
Python's $ with re.match also matches just before a single trailing newline, so tool-name validation accepted "name\n" and UriTemplate.parse accepted varnames like "foo\n". Switch both checks to re.fullmatch. Closes #3084
This commit is contained in:
parent
4fc8882c02
commit
1216c53693
2 changed files with 9 additions and 2 deletions
|
|
@ -77,7 +77,7 @@ def validate_tool_name(name: str) -> ToolNameValidationResult:
|
|||
warnings.append("Tool name starts or ends with a dot, which may cause parsing issues in some contexts")
|
||||
|
||||
# Check for invalid characters
|
||||
if not TOOL_NAME_REGEX.match(name):
|
||||
if not TOOL_NAME_REGEX.fullmatch(name):
|
||||
# Find all invalid characters (unique, preserving order)
|
||||
invalid_chars: list[str] = []
|
||||
seen: set[str] = set()
|
||||
|
|
|
|||
|
|
@ -813,7 +813,7 @@ def _parse_expression(template: str, body: str, pos: int) -> _Expression:
|
|||
explode = spec.endswith("*")
|
||||
name = spec[:-1] if explode else spec
|
||||
|
||||
if not _VARNAME_RE.match(name):
|
||||
if not _VARNAME_RE.fullmatch(name):
|
||||
raise InvalidUriTemplate(
|
||||
f"Invalid variable name {name!r} at position {pos}",
|
||||
template=template,
|
||||
|
|
|
|||
Loading…
Reference in a new issue