Skip to content

Commit

Permalink
Don't allow trailing newlines in description (#505)
Browse files Browse the repository at this point in the history
  • Loading branch information
ekralc committed Dec 23, 2022
1 parent 155fa0d commit 8718681
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/poetry/core/json/schemas/poetry-schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
"description": {
"type": "string",
"description": "Short package description.",
"pattern": "^[^\n]*$"
"pattern": "\\A[^\n]*\\Z"
},
"keywords": {
"type": "array",
Expand Down
14 changes: 11 additions & 3 deletions tests/json/test_poetry_schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,18 @@ def test_multi_url_dependencies(multi_url_object: dict[str, Any]) -> None:
assert len(validate_object(multi_url_object, "poetry-schema")) == 0


def test_multiline_description(base_object: dict[str, Any]) -> None:
bad_description = "Some multi-\nline string"
@pytest.mark.parametrize(
"bad_description",
["Some multi-\nline string", "Some multiline string\n", "\nSome multi-line string"],
)
def test_multiline_description(
base_object: dict[str, Any], bad_description: str
) -> None:
base_object["description"] = bad_description

errors = validate_object(base_object, "poetry-schema")

assert len(errors) == 1
assert errors[0] == f"[description] {bad_description!r} does not match '^[^\\n]*$'"

regex = r"\\A[^\n]*\\Z"
assert errors[0] == f"[description] {bad_description!r} does not match '{regex}'"

0 comments on commit 8718681

Please sign in to comment.