Projet

Général

Profil

0001-wcs-don-t-escape-result-of-card-cell-custom-fields-6.patch

Lauréline Guérin, 15 mars 2022 09:26

Télécharger (3,57 ko)

Voir les différences:

Subject: [PATCH 1/2] wcs: don't escape result of card cell custom fields
 (#61391)

 combo/apps/wcs/models.py |  2 +-
 tests/test_wcs.py        | 17 ++++++++++++-----
 2 files changed, 13 insertions(+), 6 deletions(-)
combo/apps/wcs/models.py
1302 1302
            return extra_context
1303 1303

  
1304 1304
        extra_context['card'] = card_data
1305
        custom_context = Context(extra_context)
1305
        custom_context = Context(extra_context, autoescape=False)
1306 1306
        custom_context.update(context)
1307 1307
        repeat_index = getattr(self, 'repeat_index', context.get('repeat_index')) or 0
1308 1308
        custom_context['repeat_index'] = repeat_index
tests/test_wcs.py
141 141
                'fieldb': True,
142 142
                'fieldc': '2020-09-28',
143 143
                'fieldd': {'filename': 'file.pdf', 'url': 'http://127.0.0.1:8999/download?f=42'},
144
                'fielde': 'lorem<strong>ipsum\n\nhello world',
144
                'fielde': "lorem<strong>ipsum\n\nhello'world",
145 145
                'fieldf': 'lorem<strong>ipsum\n\nhello world',
146 146
                'fieldg': 'test@localhost',
147 147
                'fieldh': 'https://www.example.net/',
......
2553 2553
    )
2554 2554
    assert (
2555 2555
        PyQuery(result).find('.label:contains("Field E") + .value p:last-child').text().strip()
2556
        == 'hello world'
2556
        == "hello'world"
2557 2557
    )
2558 2558

  
2559 2559
    # field F is put in a <pre>
......
2719 2719
    }
2720 2720
    cell.save()
2721 2721
    result = cell.render(context)
2722
    # check multiline text field is rendered with multiple paragraphs
2723
    # (first line "lorem<strong>ipsum" and last line ("hello'world")
2724
    # and the content is kept properly escaped.
2722 2725
    assert PyQuery(result).find('.label').text() == 'Field E'
2723 2726
    assert PyQuery(result).find('.value p:first-child').text().strip() == 'lorem<strong>ipsum'
2724
    assert PyQuery(result).find('.value p:last-child').text().strip() == 'hello world'
2727
    assert PyQuery(result).find('.value p:last-child').text().strip() == "hello'world"
2725 2728

  
2726 2729
    cell.custom_schema['cells'][0] = {
2727 2730
        'varname': 'fieldf',
......
2861 2864
        carddef_reference='default:card_model_1',
2862 2865
        custom_schema={
2863 2866
            'cells': [
2864
                {'varname': '@custom@', 'template': '<b>Foo</b> bar baz', 'display_mode': 'title'},
2867
                {
2868
                    'varname': '@custom@',
2869
                    'template': "<b>Foo</b> bar'baz {{ card.fields.fielde }}",
2870
                    'display_mode': 'title',
2871
                },
2865 2872
            ]
2866 2873
        },
2867 2874
    )
......
2874 2881

  
2875 2882
    result = cell.render(context)
2876 2883
    assert '&lt;b&gt;Foo&lt;/b&gt;' in result
2877
    assert PyQuery(result).find('h3').text() == '<b>Foo</b> bar baz'
2884
    assert PyQuery(result).find('h3').text() == "<b>Foo</b> bar'baz lorem<strong>ipsum hello'world"
2878 2885

  
2879 2886
    # test context
2880 2887
    cell.custom_schema['cells'][0][
2881
-