Saleor Core: the high performance, composable, headless commerce API.
Python cartcheckoutcommercecomposablee-commerceecommercegraphqlheadlessheadless-commercemultichannelomsorder-managementpaymentspimpythonshopshopping-cartstore
Remove html tags from product description_plaintext
Damian Wf0a6f32e468b
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex 7af11c5c5f..a4ccd078d1 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -36,6 +36,7 @@ All notable, unreleased changes to this project will be documented in this file.- Fix invalid tax rates for lines - #7058 by @IKarbowiak- Allow seeing unconfirmed orders - #7072 by @IKarbowiak- Raise GraphQLError when too big integer value is provided - #7076 by @IKarbowiak+- Remove html tags from product description_plaintext - #7094 by @d-wysocki### Breaking- Multichannel MVP: Multicurrency - #6242 by @fowczarek @d-wysockidiff --git a/saleor/core/tests/test_editorjs.py b/saleor/core/tests/test_editorjs.pyindex 9e7f500804..b2450486a5 100644--- a/saleor/core/tests/test_editorjs.py+++ b/saleor/core/tests/test_editorjs.py@@ -2,6 +2,7 @@ import warningsfrom unittest import mockimport pytest+from django.utils.html import strip_tagsfrom ..utils.editorjs import clean_editor_js@@ -34,7 +35,7 @@ def test_clean_editor_js(text):result = clean_editor_js(data, to_string=True)# then- assert result == text+ assert result == strip_tags(text)def test_clean_editor_js_no_blocks():@@ -137,7 +138,7 @@ def test_clean_editor_js_for_list():result = clean_editor_js(data, to_string=True)# then- assert result == (+ assert result == strip_tags("The Saleor Winter Sale is snowed "'<a href="https://docs.saleor.io/docs/">. Test.'"It is a block-styled editor "diff --git a/saleor/core/utils/editorjs.py b/saleor/core/utils/editorjs.pyindex 0b1966deef..a5a6f73fbd 100644--- a/saleor/core/utils/editorjs.py+++ b/saleor/core/utils/editorjs.py@@ -2,6 +2,7 @@ import reimport warningsfrom typing import Dict, Optional+from django.utils.html import strip_tagsfrom urllib3.util import parse_urlBLACKLISTED_URL_SCHEMES = ("javascript",)@@ -38,7 +39,7 @@ def clean_editor_js(definitions: Optional[Dict], *, to_string: bool = False):continuenew_text = clean_text_data(item)if to_string:- string += new_text+ string += strip_tags(new_text)else:blocks[index]["data"]["items"][item_index] = new_textelse:@@ -47,7 +48,7 @@ def clean_editor_js(definitions: Optional[Dict], *, to_string: bool = False):continuenew_text = clean_text_data(text)if to_string:- string += new_text+ string += strip_tags(new_text)else:blocks[index]["data"]["text"] = new_textdiff --git a/saleor/graphql/product/tests/test_product.py b/saleor/graphql/product/tests/test_product.pyindex 01cb6a49ce..d743b4db80 100644--- a/saleor/graphql/product/tests/test_product.py+++ b/saleor/graphql/product/tests/test_product.py@@ -7,6 +7,7 @@ import grapheneimport pytestfrom django.core.exceptions import ValidationErrorfrom django.utils.dateparse import parse_datetime+from django.utils.html import strip_tagsfrom django.utils.text import slugifyfrom freezegun import freeze_timefrom graphql_relay import to_global_id@@ -3959,6 +3960,9 @@ def test_update_product(color_attribute,):query = MUTATION_UPDATE_PRODUCT+ expected_other_description_json = other_description_json+ text = expected_other_description_json["blocks"][0]["data"]["text"]+ expected_other_description_json["blocks"][0]["data"]["text"] = strip_tags(text)other_description_json = json.dumps(other_description_json)product_id = graphene.Node.to_global_id("Product", product.pk)@@ -3998,7 +4002,7 @@ def test_update_product(assert data["productErrors"] == []assert data["product"]["name"] == product_nameassert data["product"]["slug"] == product_slug- assert data["product"]["description"] == other_description_json+ assert data["product"]["description"] == json.dumps(expected_other_description_json)assert data["product"]["chargeTaxes"] == product_charge_taxesassert data["product"]["taxType"]["taxCode"] == product_tax_rateassert not data["product"]["category"]["name"] == category.namediff --git a/saleor/tests/fixtures.py b/saleor/tests/fixtures.pyindex cc79669ee1..a48f513890 100644--- a/saleor/tests/fixtures.py+++ b/saleor/tests/fixtures.py@@ -3472,7 +3472,7 @@ def other_description_json():{"key": "","data": {- "text": "A GRAPHQL-FIRST ECOMMERCE PLATFORM FOR PERFECTIONISTS",+ "text": "A GRAPHQL-FIRST <b>ECOMMERCE</b> PLATFORM FOR PERFECTIONISTS",},"text": "A GRAPHQL-FIRST ECOMMERCE PLATFORM FOR PERFECTIONISTS","type": "header-two",