--[[ What is hidden and what is shown: styles over the layers of a declaration block, formatting elements carried over an implied end tag, the tags limit. ]] context("HTML visibility after implied end tags and important styles", function() local rspamd_task = require "rspamd_task" local function look(body, style) local msg = "From: a@example.com\r\nSubject: t\r\nMIME-Version: 1.0\r\n" .. "Content-Type: text/html; charset=utf-8\r\n\r\n" .. '
' .. body .. "\r\n" local _, task = rspamd_task.load_from_string(msg, rspamd_config) task:process_message() local tp = task:get_text_parts()[1] local res = { visible = tostring(tp:get_content()), invisible = tostring(tp:get_html():get_invisible()), } task:destroy() return res end local function shown(res, word) return res.visible:find(word, 1, true) ~= nil end local function hidden(res, word) return res.invisible:find(word, 1, true) ~= nil and not shown(res, word) end -- Hidden by what is not `display` local forced = { { 'opacity', 'HID' }, { 'a text indent', 'HID' }, { 'an important offset', 'HID' }, { 'opacity inline and display in a class', 'HID', '.c{display:block !important}' }, { 'opacity and display in a class', 'HID', '.c{opacity:0;display:block !important}' }, { 'a clip in a class', 'HID', '.c{clip-path:inset(100%);display:block !important}' }, { 'opacity of a parent', 'HID' }, } for _, c in ipairs(forced) do test("An important display does not show what is hidden by " .. c[1], function() local res = look('' .. c[2] .. 'shown
', c[3]) assert_true(hidden(res, 'HID'), res.visible) assert_true(shown(res, 'shown')) end) end test("An important opacity wins over a normal one", function() local res = look('SEEN') assert_true(shown(res, 'SEEN')) res = look('SEEN') assert_true(shown(res, 'SEEN')) end) -- Formatting elements are open again after an implied end tag test("The colour of a font goes on in the paragraphs that follow", function() local res = look('line one line two' ..
' line three
shownHID0 RECON1 RECON2 HID hid2 SEEN HID bold next plain third para x
')
assert_true(shown(res, 'one'))
assert_true(hidden(res, 'L1'), res.visible)
assert_true(hidden(res, 'L2'), res.visible)
end)
test("The end tag of a formatting element ends it for what follows", function()
local res = look('
')
assert_true(hidden(res, 'HID'))
assert_true(shown(res, 'CELL'), res.visible)
end)
test("Plain formatting changes nothing of what is shown", function()
local res = look('CELL
SEEN1')
assert_true(hidden(res, 'HID'))
assert_true(shown(res, 'SEEN1'))
end)
-- Small things
test("A numeric no-break space is the space that its name gives", function()
local res = look('a b c d e f')
assert_nil(res.visible:find('\194\160', 1, true))
assert_not_nil(res.visible:find('a b', 1, true))
assert_not_nil(res.visible:find('e f', 1, true))
end)
test("Three digits without a sharp are not a short colour", function()
-- `fff` is #0f0f0f by the legacy rules: dark on white
local res = look('' .. pad .. '
')
assert_true(shown(res, 'DARK'), res.visible)
assert_false(shown(res, 'WHITE'))
end)
end)
DARK ' ..
'WHITE