From 346350dcf0c5d606b0380fddf9baba1dc3bba2dc Mon Sep 17 00:00:00 2001 From: chaojie Date: Sun, 26 Mar 2023 20:33:53 +0800 Subject: [PATCH 1/2] Normaliza metadata the description field when contain line break --- backend/src/hatchling/metadata/core.py | 3 ++- tests/backend/metadata/test_core.py | 5 +++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/backend/src/hatchling/metadata/core.py b/backend/src/hatchling/metadata/core.py index d05ff114d..45d8a66a5 100644 --- a/backend/src/hatchling/metadata/core.py +++ b/backend/src/hatchling/metadata/core.py @@ -462,7 +462,8 @@ def description(self) -> str: if not isinstance(description, str): message = 'Field `project.description` must be a string' raise TypeError(message) - + if '\n' or '\r\n' in description: + description = description.replace('\r\n', ' ').replace('\n', ' ') self._description = description return self._description diff --git a/tests/backend/metadata/test_core.py b/tests/backend/metadata/test_core.py index 84e13f2b8..3ba39af9d 100644 --- a/tests/backend/metadata/test_core.py +++ b/tests/backend/metadata/test_core.py @@ -338,6 +338,11 @@ def test_custom(self, isolation): assert metadata.core.description == metadata.core.description == 'foo' + def test_normaliza(self, isolation): + metadata = ProjectMetadata(str(isolation), None, {'project': {'description': '\nfirst line.\r\nsecond line'}}) + + assert metadata.core.description == metadata.core.description == ' first line. second line' + class TestReadme: def test_dynamic(self, isolation): From bd57d7cce734510af53fe33598cf2465ef3e6dcb Mon Sep 17 00:00:00 2001 From: Ofek Lev Date: Sun, 2 Apr 2023 13:52:54 -0400 Subject: [PATCH 2/2] Apply suggestions from code review --- backend/src/hatchling/metadata/core.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/backend/src/hatchling/metadata/core.py b/backend/src/hatchling/metadata/core.py index 45d8a66a5..d9787b176 100644 --- a/backend/src/hatchling/metadata/core.py +++ b/backend/src/hatchling/metadata/core.py @@ -462,9 +462,7 @@ def description(self) -> str: if not isinstance(description, str): message = 'Field `project.description` must be a string' raise TypeError(message) - if '\n' or '\r\n' in description: - description = description.replace('\r\n', ' ').replace('\n', ' ') - self._description = description + self._description = ' '.join(description.splitlines()) return self._description