Enforced   breaks inline CSS with !important
Closed, ResolvedPublic

Description

Author: kalan.001

Description:
It's sometimes needed to enter !important in inline CSS styles. But if you try to do it, for example, with this code:

<div style="width:50% !important">

the generated wikitext will contain

<div style="width:50%&#160;!important">

This &#160; breaks style and some functionality.


Version: 1.12.x
Severity: normal
URL: http://ru.wikipedia.org/wiki/Template_talk:Ambox
See Also:
https://bugzilla.wikimedia.org/show_bug.cgi?id=3158

bzimport added projects: MediaWiki-Parser, Easy.Via ConduitNov 21 2014, 10:00 PM
bzimport added a subscriber: wikibugs-l.
bzimport set Reference to bz11874.
bzimport created this task.Via LegacyNov 5 2007, 6:48 AM
bzimport added a comment.Via ConduitMar 24 2008, 6:23 PM

nicdumz wrote:

proposed patch

It came from the preg_replace operated in parse() on the HTML :

'/(.) (?=\\?|:|;|!|%|\\302\\273)/' => '\\1&nbsp;\\2'

One-line patch, tested on a local wiki : it's adding a preg_replace rule :

'/&nbsp;(!important)/' => ' \\1',

To convert "!important" magic word back to its previous valid syntax. Yes, in that particular case, it converts " !important" to "&nbsp;!important", and then back to " !important", but I don't see a light way to improve the first regexp to avoid converting the space before " !important".

Cheers,

Nicolas.

Attached: 11874.diff

brion added a comment.Via ConduitMar 24 2008, 6:32 PM

Looks good! Applied with parser test cases in r32375

brion added a comment.Via ConduitMar 24 2008, 6:45 PM

Slight modification in r32377 for the case where space is present between ! and important

bzimport added a comment.Via ConduitMar 24 2008, 8:03 PM

ayg wrote:

Why does parse() mangle spaces in style attributes to begin with? Surely that's got to cause other problems? As for the fix in r32377, won't "width:50% ! important" become "width:50%&nbsp;!&nbsp;important" and so evade the fix?

bzimport added a comment.Via ConduitMar 24 2008, 8:08 PM

ayg wrote:

(In reply to comment #4)

As for the fix in r32377, won't "width:50%
! important" become "width:50%&nbsp;!&nbsp;important" and so evade the fix?

No, of course not, never mind me. That only applies to spaces *before* exclamation points. Still seems like the best way to fix this would be to avoid HTML attributes, or at least some of them (like style attributes).

brion added a comment.Via ConduitMar 24 2008, 8:17 PM

Presumably so that title, alt, etc texts will also wrap properly.

Perhaps such attributes could be whitelisted, which would solve this in a more long-term way.

bzimport added a comment.Via ConduitMar 24 2008, 8:24 PM

ayg wrote:

Yes, some attributes should have this, but not in general. I suspect that the replace could potentially even affect class declarations, although they'd be fairly funny class declarations. For style, the only things that should be replaced by this are quoted strings for properties like content.

Wouldn't similar issues to the one fixed occur with styles declared like "width : 50%"? That must be fairly common.

bzimport added a comment.Via ConduitApr 9 2008, 12:47 AM

ui2t5v002 wrote:

This does screw up things like style="border : solid;" It should not apply inside HTML tags by default.

Mormegil added a comment.Via ConduitNov 12 2008, 10:18 PM

Definitely. See bug #3158

Add Comment

Column Prototype
This is a very early prototype of a persistent column. It is not expected to work yet, and leaving it open will activate other new features which will break things. Press "\" (backslash) on your keyboard to close it now.