Projet

Général

Profil

0001-wcs-display-richtext-field-as-safe-69271.patch

Lauréline Guérin, 19 septembre 2022 16:46

Télécharger (5,2 ko)

Voir les différences:

Subject: [PATCH] wcs: display richtext field as safe (#69271)

 .../templates/combo/wcs/card-field-value.html |  2 ++
 tests/wcs/test_card.py                        | 25 ++++++++++++++++---
 tests/wcs/utils.py                            |  2 ++
 3 files changed, 26 insertions(+), 3 deletions(-)
combo/apps/wcs/templates/combo/wcs/card-field-value.html
15 15
  {% else %}
16 16
    <a href="{% make_public_url url=value.url %}" download="{{ value.filename }}">{{ value.filename }}</a>
17 17
  {% endif %}
18
{% elif field.type == "richtext" %}
19
  {{ value|safe }}
18 20
{% else %}
19 21
  {{ value|default:""|urlize }}
20 22
{% endif %}
tests/wcs/test_card.py
855 855
        {'varname': 'fieldf'},
856 856
        {'varname': 'fieldg'},
857 857
        {'varname': 'fieldh'},
858
        {'varname': 'fieldi'},
858 859
        {'varname': 'unknown'},
859 860
        {'varname': 'user:name'},
860 861
        {'varname': 'user:email'},
......
867 868

  
868 869
    result = cell.render(context)
869 870
    assert PyQuery(result).find('ul li') == []
870
    assert len(PyQuery(result).find('table tr td')) == 13 * 3
871
    assert len(PyQuery(result).find('table tr td')) == 14 * 3
871 872
    assert [PyQuery(td).text() for td in PyQuery(result).find('table tr:first-child td')] == [
872 873
        '<i>a</i>',
873 874
        'yes',
......
878 879
        "lorem<strong>ipsum hello world",
879 880
        'test@localhost',
880 881
        'https://www.example.net/',
882
        "loremipsum\nhello'world",
881 883
        'User Foo Bar',
882 884
        'foo@bar.com',
883 885
        'User',
......
895 897
        PyQuery(result).find('table tr:first-child td:nth-child(9) a').attr['href']
896 898
        == 'https://www.example.net/'
897 899
    )
898
    assert PyQuery(result).find('table tr:first-child td:nth-child(11) a').text().strip() == 'foo@bar.com'
900
    assert PyQuery(result).find('table tr:first-child td:nth-child(10) p:first-child').text() == 'loremipsum'
899 901
    assert (
900
        PyQuery(result).find('table tr:first-child td:nth-child(11) a').attr['href'] == 'mailto:foo@bar.com'
902
        PyQuery(result).find('table tr:first-child td:nth-child(10) p:first-child strong').text() == 'ipsum'
903
    )
904
    assert PyQuery(result).find('table tr:first-child td:nth-child(10) p:last-child').text() == "hello'world"
905
    assert PyQuery(result).find('table tr:first-child td:nth-child(12) a').text().strip() == 'foo@bar.com'
906
    assert (
907
        PyQuery(result).find('table tr:first-child td:nth-child(12) a').attr['href'] == 'mailto:foo@bar.com'
901 908
    )
902 909

  
903 910

  
......
1737 1744
    assert PyQuery(result).find('.label').text() == 'Field F'
1738 1745
    assert PyQuery(result).find('.value pre').text() == 'lorem<strong>ipsum hello world'
1739 1746

  
1747
    cell.custom_schema['cells'][0] = {
1748
        'varname': 'fieldi',
1749
        'field_content': 'label-and-value',
1750
        'display_mode': 'text',
1751
    }
1752
    cell.save()
1753
    result = cell.render(context)
1754
    assert PyQuery(result).find('.label').text() == 'Field I'
1755
    assert PyQuery(result).find('.value p:first-child').text() == 'loremipsum'
1756
    assert PyQuery(result).find('.value p:first-child strong').text() == 'ipsum'
1757
    assert PyQuery(result).find('.value p:last-child').text() == "hello'world"
1758

  
1740 1759
    cell.custom_schema['cells'][0] = {
1741 1760
        'varname': 'fieldg',
1742 1761
        'field_content': 'label-and-value',
tests/wcs/utils.py
106 106
                'fieldf': 'lorem<strong>ipsum\n\nhello world',
107 107
                'fieldg': 'test@localhost',
108 108
                'fieldh': 'https://www.example.net/',
109
                'fieldi': "<p>lorem<strong>ipsum</p><p>hello'world</p>",
109 110
                'related': 'Foo Bar',
110 111
                'related_raw': 42,
111 112
                'related_structured': {'id': 42, 'text': 'blah'},
......
230 231
            {'label': 'Field F', 'varname': 'fieldf', 'type': 'text', 'pre': True},
231 232
            {'label': 'Field G', 'varname': 'fieldg', 'type': 'email'},
232 233
            {'label': 'Field H', 'varname': 'fieldh', 'type': 'string'},
234
            {'label': 'Field I', 'varname': 'fieldi', 'type': 'richtext'},
233 235
            {'label': 'Empty', 'varname': 'empty', 'type': 'string'},
234 236
            {'label': 'Related', 'varname': 'related', 'type': 'item'},
235 237
            {'label': 'Page', 'type': 'page'},
236
-