forked from python-poetry/poetry
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Instead of relying on regular expressions, this patch leverages Python’s builtin `email.utils.parseaddr()` functionality to parse an RFC-822-compliant email address string into its name and address parts. This should also resolve issues with special characters in the name part; see issues python-poetry#370 and python-poetry#798. python-poetry#370 python-poetry#798
- Loading branch information
Showing
6 changed files
with
86 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,6 +6,7 @@ | |
from typing import List | ||
from typing import Tuple | ||
|
||
from poetry.utils.helpers import parse_author | ||
from .command import Command | ||
from .env_command import EnvCommand | ||
|
||
|
@@ -294,15 +295,13 @@ def _format_requirements(self, requirements): # type: (List[str]) -> dict | |
return requires | ||
|
||
def _validate_author(self, author, default): | ||
from poetry.packages.package import AUTHOR_REGEX | ||
|
||
author = author or default | ||
|
||
if author in ["n", "no"]: | ||
return | ||
|
||
m = AUTHOR_REGEX.match(author) | ||
if not m: | ||
name, email = parse_author(author) | ||
if not name: | ||
raise ValueError( | ||
"Invalid author string. Must be in the format: " | ||
"John Smith <[email protected]>" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,3 +14,11 @@ def test_package_authors(): | |
package.authors.insert(0, "John Doe") | ||
assert package.author_name == "John Doe" | ||
assert package.author_email is None | ||
|
||
|
||
def test_package_authors_with_fancy_unicode(): | ||
package = Package("foo", "0.1.0") | ||
|
||
package.authors.append("my·fancy·company <[email protected]>") | ||
assert package.author_name == "my·fancy·company" | ||
assert package.author_email == "[email protected]" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,9 @@ | ||
# -*- coding: utf-8 -*- | ||
from __future__ import unicode_literals | ||
|
||
from poetry.utils.helpers import get_http_basic_auth | ||
from poetry.utils.helpers import parse_requires | ||
from poetry.utils.helpers import parse_author | ||
|
||
|
||
def test_parse_requires(): | ||
|
@@ -66,3 +70,51 @@ def test_get_http_basic_auth_without_password(config): | |
|
||
def test_get_http_basic_auth_missing(config): | ||
assert get_http_basic_auth(config, "foo") is None | ||
|
||
|
||
def test_parse_author_simple_name_and_email(): | ||
name, email = parse_author("John Doe <[email protected]>") | ||
assert name == "John Doe" | ||
assert email == "[email protected]" | ||
|
||
|
||
def test_parse_author_simple_name_only(): | ||
name, email = parse_author("John Doe") | ||
assert name == "John Doe" | ||
assert email is None | ||
|
||
|
||
def test_parse_author_ascii_specialchars_name_and_email(): | ||
name, email = parse_author("R&D <[email protected]>") | ||
assert name == "R&D" | ||
assert email == "[email protected]" | ||
|
||
|
||
def test_parse_author_ascii_specialchars_name_only(): | ||
name, email = parse_author("R&D") | ||
assert name == "R&D" | ||
assert email is None | ||
|
||
|
||
def test_parse_author_unicode_name_and_email(): | ||
name, email = parse_author("my·fancy·corp <[email protected]>") | ||
assert name == "my·fancy·corp" | ||
assert email == "[email protected]" | ||
|
||
|
||
def test_parse_author_unicode_name_only(): | ||
name, email = parse_author("my·fancy·corp") | ||
assert name == "my·fancy·corp" | ||
assert email is None | ||
|
||
|
||
def test_parse_author_email_only_with_angular_brackets(): | ||
name, email = parse_author("<[email protected]>") | ||
assert name is None | ||
assert email == "[email protected]" | ||
|
||
|
||
def test_parse_author_email_only_without_angular_brackets(): | ||
name, email = parse_author("[email protected]") | ||
assert name is None | ||
assert email == "[email protected]" |