From f6a34b954aecd04ae540f7da693879ae397c083e Mon Sep 17 00:00:00 2001 From: Donald Stufft Date: Sat, 11 May 2019 21:06:31 -0400 Subject: [PATCH] Fail uploads with an invalid description --- tests/unit/forklift/test_legacy.py | 1 - warehouse/forklift/legacy.py | 45 +++++++++++++++--------------- 2 files changed, 22 insertions(+), 24 deletions(-) diff --git a/tests/unit/forklift/test_legacy.py b/tests/unit/forklift/test_legacy.py index 577fb8473d0b..812ad8e27c5c 100644 --- a/tests/unit/forklift/test_legacy.py +++ b/tests/unit/forklift/test_legacy.py @@ -919,7 +919,6 @@ def test_fails_with_invalid_names(self, pyramid_config, db_request, name): "for more information." ).format(name) - @pytest.mark.xfail(reason="https://github.com/pypa/warehouse/issues/4079") @pytest.mark.parametrize( ("description_content_type", "description", "message"), [ diff --git a/warehouse/forklift/legacy.py b/warehouse/forklift/legacy.py index 171d8b85a05c..fa8456769be7 100644 --- a/warehouse/forklift/legacy.py +++ b/warehouse/forklift/legacy.py @@ -934,33 +934,32 @@ def file_upload(request): rendered = None if form.description.data: description_content_type = form.description_content_type.data - # if not description_content_type: - # description_content_type = "text/x-rst" + if not description_content_type: + description_content_type = "text/x-rst" + rendered = readme.render( - form.description.data, description_content_type # use_fallback=False + form.description.data, description_content_type, use_fallback=False ) # Uploading should prevent broken rendered descriptions. - # Temporarily disabled, see - # https://github.com/pypa/warehouse/issues/4079 - # if rendered is None: - # if form.description_content_type.data: - # message = ( - # "The description failed to render " - # "for '{description_content_type}'." - # ).format(description_content_type=description_content_type) - # else: - # message = ( - # "The description failed to render " - # "in the default format of reStructuredText." - # ) - # raise _exc_with_message( - # HTTPBadRequest, - # "{message} See {projecthelp} for more information.".format( - # message=message, - # projecthelp=request.help_url(_anchor="description-content-type"), - # ), - # ) from None + if rendered is None: + if form.description_content_type.data: + message = ( + "The description failed to render " + "for '{description_content_type}'." + ).format(description_content_type=description_content_type) + else: + message = ( + "The description failed to render " + "in the default format of reStructuredText." + ) + raise _exc_with_message( + HTTPBadRequest, + "{message} See {projecthelp} for more information.".format( + message=message, + projecthelp=request.help_url(_anchor="description-content-type"), + ), + ) from None try: canonical_version = packaging.utils.canonicalize_version(form.version.data)