wcs: replace newlines by spaces in title and headers (#86308)
gitea/combo/pipeline/head This commit looks good Details

This commit is contained in:
Lauréline Guérin 2024-02-07 17:03:40 +01:00
parent ec57e7c060
commit 871befa11c
No known key found for this signature in database
GPG Key ID: 1FAB9B9B4F93D473
3 changed files with 18 additions and 1 deletions

View File

@ -1702,6 +1702,8 @@ class WcsCardCell(CardMixin, CellBase):
if card_data.get('digests', {}).get(digest_name):
page_title_from_cell = card_data['digests'][digest_name]
if page_title_from_cell:
# header values can't contain newlines
page_title_from_cell = page_title_from_cell.replace('\n', ' ')
custom_context['request'].page_title_from_cell = page_title_from_cell
def set_data_from_repeated_cell(self, cell, context):

View File

@ -2337,6 +2337,17 @@ def test_card_cell_card_mode_render(mock_send, context, app):
resp = app.get(page.get_online_url() + '11/', headers={'User-Agent': 'testbot'})
assert resp.pyquery('title').text() == 'afoo afoo afoo | Combo - xxx'
# custom-view:bar contains \n, header values can't contain newlines
cell.carddef_reference = 'default:card_model_1:bar'
cell.save()
resp = app.get(page.get_online_url() + '11/')
cell_resp = app.get(
resp.pyquery('.wcs-card-cell').attr['data-ajax-cell-url']
+ '?ctx='
+ resp.pyquery('.wcs-card-cell').attr['data-extra-context']
)
assert cell_resp.headers['X-Page-Title'] == 'a a a' # \n are replaced by spaces
@mock.patch('requests.Session.send', side_effect=mocked_requests_send)
def test_card_cell_card_mode_render_text_field(mock_send, context):

View File

@ -108,7 +108,11 @@ WCS_CARDS_DATA = {
'display_id': '10-11',
'display_name': 'Card Model 1 - n°10-11',
'digest': 'a a a',
'digests': {'default': 'a a a', 'custom-view:foo': 'afoo afoo afoo'},
'digests': {
'default': 'a a a',
'custom-view:foo': 'afoo afoo afoo',
'custom-view:bar': 'a\na\na',
},
'text': 'aa',
'receipt_time': '2021-11-29T14:33:37',
'last_update_time': '2023-07-24T16:04:24',