diff options
| author | Jason R. Coombs <jaraco@jaraco.com> | 2021-05-09 10:57:31 -0400 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2021-05-09 10:57:31 -0400 |
| commit | 8771b840b0a2d56c53cd86caf30b4776c8c031ed (patch) | |
| tree | f9d926e53120f2a3a59e8d47c0f664aaf1aa8625 /setuptools | |
| parent | ed60ed05e9508729f25e1f3060a9fd2293999859 (diff) | |
| parent | c36033859ec2f7d9034a93c363ffc858ffbae172 (diff) | |
| download | python-setuptools-git-8771b840b0a2d56c53cd86caf30b4776c8c031ed.tar.gz | |
Merge pull request #2640 from cdce8p/license
Add escaping to license field
Diffstat (limited to 'setuptools')
| -rw-r--r-- | setuptools/dist.py | 5 | ||||
| -rw-r--r-- | setuptools/tests/test_dist.py | 4 | ||||
| -rw-r--r-- | setuptools/tests/test_egg_info.py | 31 |
3 files changed, 38 insertions, 2 deletions
diff --git a/setuptools/dist.py b/setuptools/dist.py index c7af35dc..49501263 100644 --- a/setuptools/dist.py +++ b/setuptools/dist.py @@ -120,7 +120,7 @@ def read_pkg_file(self, file): self.author_email = _read_field_from_msg(msg, 'author-email') self.maintainer_email = None self.url = _read_field_from_msg(msg, 'home-page') - self.license = _read_field_from_msg(msg, 'license') + self.license = _read_field_unescaped_from_msg(msg, 'license') if 'download-url' in msg: self.download_url = _read_field_from_msg(msg, 'download-url') @@ -188,7 +188,8 @@ def write_pkg_file(self, file): # noqa: C901 # is too complex (14) # FIXME if attr_val is not None: write_field(field, attr_val) - write_field('License', self.get_license()) + license = rfc822_escape(self.get_license()) + write_field('License', license) if self.download_url: write_field('Download-URL', self.download_url) for project_url in self.project_urls.items(): diff --git a/setuptools/tests/test_dist.py b/setuptools/tests/test_dist.py index dcec1734..e09ed4cb 100644 --- a/setuptools/tests/test_dist.py +++ b/setuptools/tests/test_dist.py @@ -116,6 +116,10 @@ def __read_test_cases(): ('Metadata Version 2.1: Long Description Content Type', params( long_description_content_type='text/x-rst; charset=UTF-8', )), + ('License', params(license='MIT', )), + ('License multiline', params( + license='This is a long license \nover multiple lines', + )), pytest.param( 'Metadata Version 2.1: Provides Extra', params(provides_extras=['foo', 'bar']), diff --git a/setuptools/tests/test_egg_info.py b/setuptools/tests/test_egg_info.py index 80d35774..5283954b 100644 --- a/setuptools/tests/test_egg_info.py +++ b/setuptools/tests/test_egg_info.py @@ -886,6 +886,37 @@ class TestEggInfo: assert expected_line in pkg_info_lines assert 'Metadata-Version: 1.2' in pkg_info_lines + def test_license(self, tmpdir_cwd, env): + """Test single line license.""" + self._setup_script_with_requires( + "license='MIT'," + ) + code, data = environment.run_setup_py( + cmd=['egg_info'], + pypath=os.pathsep.join([env.paths['lib'], str(tmpdir_cwd)]), + data_stream=1, + ) + egg_info_dir = os.path.join('.', 'foo.egg-info') + with open(os.path.join(egg_info_dir, 'PKG-INFO')) as pkginfo_file: + pkg_info_lines = pkginfo_file.read().split('\n') + assert 'License: MIT' == pkg_info_lines[7] + + def test_license_escape(self, tmpdir_cwd, env): + """Test license is escaped correctly if longer than one line.""" + self._setup_script_with_requires( + "license='This is a long license text \\nover multiple lines'," + ) + code, data = environment.run_setup_py( + cmd=['egg_info'], + pypath=os.pathsep.join([env.paths['lib'], str(tmpdir_cwd)]), + data_stream=1, + ) + egg_info_dir = os.path.join('.', 'foo.egg-info') + with open(os.path.join(egg_info_dir, 'PKG-INFO')) as pkginfo_file: + pkg_info_lines = pkginfo_file.read().split('\n') + assert 'License: This is a long license text ' == pkg_info_lines[7] + assert ' over multiple lines' == pkg_info_lines[8] + def test_python_requires_egg_info(self, tmpdir_cwd, env): self._setup_script_with_requires( """python_requires='>=2.7.12',""") |
