from goodnews.markup import sanitize_reply_html as s, reply_html_to_text as t2 def test_keeps_allowed_formatting_and_normalizes_tags(): out = s("bold and it and x and y") assert out == "bold and it and x and y" def test_lists_and_paragraphs(): assert s("") == "" assert s("
  1. one
") == "
  1. one
" assert s("
line
") == "

line

" # div canonicalised to p assert s("a
b") == "a
b" def test_font_size_whitelist(): assert s('big') == 'big' # off-whitelist size → span dropped, text kept assert s('huge') == "huge" # normalised to a safe span assert s('x') == 'x' def test_strips_dangerous_and_arbitrary(): # script content discarded entirely assert "alert" not in s("hi") and s("hi") == "hi" # links dropped, text kept; no href/onclick survive out = s('click') assert out == "click" # arbitrary styles/colors stripped, content kept assert s('z') == "z" # escapes stray angle brackets in text assert s("2 < 3 & 4 > 1") == "2 < 3 & 4 > 1" def test_empty(): assert s("") == "" and s("

") == "" and s("
") == "" def test_html_to_text(): assert t2("

hi there

") == "hi there" assert t2("") == "- a\n- b" assert t2('big') == "big" def test_autocloses_unclosed_tags(): assert s("bold") == "bold" assert s("

hi") == "

hi

" assert s("