Skip to content

Commit

Permalink
Merge pull request #1935 from yamagen0915/fix_getting_author_name
Browse files Browse the repository at this point in the history
Add error handling for malfoemed author
  • Loading branch information
finswimmer authored Jun 26, 2020
2 parents cd6da2c + 6a0ac4a commit 413c07e
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
12 changes: 12 additions & 0 deletions poetry/packages/package.py
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,12 @@ def _get_author(self): # type: () -> dict

m = AUTHOR_REGEX.match(normalize("NFC", self._authors[0]))

if m is None:
raise ValueError(
"Invalid author string. Must be in the format: "
"John Smith <[email protected]>"
)

name = m.group("name")
email = m.group("email")

Expand All @@ -174,6 +180,12 @@ def _get_maintainer(self): # type: () -> dict

m = AUTHOR_REGEX.match(normalize("NFC", self._maintainers[0]))

if m is None:
raise ValueError(
"Invalid maintainer string. Must be in the format: "
"John Smith <[email protected]>"
)

name = m.group("name")
email = m.group("email")

Expand Down
13 changes: 13 additions & 0 deletions tests/packages/test_package.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,19 @@ def test_package_authors():
assert package.author_email is None


def test_package_authors_invalid():
package = Package("foo", "0.1.0")

package.authors.insert(0, "<John Doe")
with pytest.raises(ValueError) as e:
package.author_name

assert (
str(e.value)
== "Invalid author string. Must be in the format: John Smith <[email protected]>"
)


@pytest.mark.parametrize("category", ["main", "dev"])
def test_package_add_dependency_vcs_category(category):
package = Package("foo", "0.1.0")
Expand Down

0 comments on commit 413c07e

Please sign in to comment.