20232baf06
Restore the board header add button to the task side panel while keeping footer quick entry. Add safe, persisted goal text formatting and self-hosted Project font preferences with shared help updates and regression coverage.
38 lines
1.8 KiB
Python
38 lines
1.8 KiB
Python
import json
|
|
import unittest
|
|
from app.modules.project import store
|
|
|
|
|
|
def rich(runs):
|
|
return store.GOAL_RICH_PREFIX + json.dumps(runs, ensure_ascii=False)
|
|
|
|
|
|
class GoalRichTextTests(unittest.TestCase):
|
|
def test_selected_styles_are_safe_and_legacy_text_stays_literal(self):
|
|
body = rich([{"text": "<img src=x onerror=alert(1)>", "bold": True,
|
|
"color": "#FF0000", "size": 20, "onclick": "alert(1)"},
|
|
{"text": " untouched", "color": "url(javascript:x)", "size": 99}])
|
|
stored = store.validate_goal_text(body)
|
|
html = store.goal_text_html(stored)
|
|
assert '<img' in html and '<img' not in html
|
|
assert 'font-weight:700' in html and 'color:#ff0000' in html and 'font-size:20px' in html
|
|
assert 'javascript' not in html and 'onclick' not in stored and '99px' not in html
|
|
assert store.goal_text_html('<b>legacy</b>') == '<b>legacy</b>'
|
|
|
|
|
|
def test_rich_merge_preserves_styles_and_plain_meeting_plan(self):
|
|
value = store.merge_goal_texts(['first', rich([{"text": "second", "bold": True, "size": 18}])])
|
|
assert store.goal_text_plain(value) == 'first\nsecond'
|
|
assert 'font-size:18px' in store.goal_text_html(value)
|
|
assert store.merge_goal_texts(['a', 'b']) == 'a\nb'
|
|
assert store.validate_goal_text(rich([{"text": " "}])) == ''
|
|
|
|
|
|
def test_rich_payload_limits_and_malformed_data(self):
|
|
with self.assertRaises(ValueError):
|
|
store.validate_goal_text(rich([{"text": "x" * (store.GOAL_TEXT_MAX + 1)}]))
|
|
with self.assertRaises(ValueError):
|
|
store.validate_goal_text(store.GOAL_RICH_PREFIX + '{"unexpected":1}')
|
|
with self.assertRaises(ValueError):
|
|
store.validate_goal_text(store.GOAL_RICH_PREFIX + '[broken')
|