Skip to content

Commit

Permalink
Fix bug where HTML messages with @media styles could moddify style of…
Browse files Browse the repository at this point in the history
… page body (#5811)
  • Loading branch information
alecpl committed Jun 28, 2017
1 parent 6d53c6b commit 39fa590
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ CHANGELOG Roundcube Webmail
- Password: Fix compatibility with PHP 7+ in cpanel_webmail driver (#5820)
- Fix decoding non-ascii attachment names from TNEF attachments (#5646, #5799)
- Fix uninitialized string offset in rcube_utils::bin2ascii() and make sure rcube_utils::random_bytes() result has always requested length (#5788)
- Fix bug where HTML messages with @media styles could moddify style of page body (#5811)

RELEASE 1.3.0
-------------
Expand Down
5 changes: 4 additions & 1 deletion program/lib/Roundcube/rcube_utils.php
Original file line number Diff line number Diff line change
Expand Up @@ -430,7 +430,10 @@ public static function mod_css_styles($source, $container_id, $allow_remote = fa
$source = preg_replace(
array(
'/(^\s*<\!--)|(-->\s*$)/m',
'/(^\s*|,\s*|\}\s*)([a-z0-9\._#\*][a-z0-9\.\-_]*)/im',
// (?!##str) below is to not match with ##str_replacement_0##
// from rcube_string_replacer used above, this is needed for
// cases like @media { body { position: fixed; } } (#5811)
'/(^\s*|,\s*|\}\s*|\{\s*)((?!##str)[a-z0-9\._#\*][a-z0-9\.\-_]*)/im',
'/'.preg_quote($container_id, '/').'\s+body/i',
),
array(
Expand Down
1 change: 1 addition & 0 deletions tests/Framework/Utils.php
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,7 @@ function test_mod_css_styles()

$this->assertContains('#rcmbody table[class=w600]', $mod, 'Replace styles nested in @media block');
$this->assertContains('#rcmbody {width:600px', $mod, 'Replace body selector nested in @media block');
$this->assertContains('#rcmbody {min-width:474px', $mod, 'Replace body selector nested in @media block (#5811)');
}

/**
Expand Down
1 change: 1 addition & 0 deletions tests/src/media.css
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ div, p, a, li, td { -webkit-text-size-adjust:none; }
body {width:600px !important; margin:auto !important;}
.pict img {max-width:540px !important; height:auto !important;}
}
@media screen and (max-width:600px) { body {min-width:474px !important;} }
h1{ font-weight:bold; font-size:14px;color:#3c3c3c ;margin:0px; }
h2{ color:#8DB048 ; font-size:14px; font-weight:bold; margin-top:20px; border-bottom:1px solid #d6d6d6; padding-bottom:4px; }
h3{ color:#7e7e7e ; font-size:14px; font-weight:bold; margin:20px 0px 0px 0px; border-bottom:1px solid #d6d6d6; padding-bottom:0px 0px 4px 0px; }
Expand Down

0 comments on commit 39fa590

Please sign in to comment.