Last modified: 2014-06-27 03:56:51 UTC

Wikimedia Bugzilla is closed!

Wikimedia migrated from Bugzilla to Phabricator. Bug reports are handled in Wikimedia Phabricator.
This static website is read-only and for historical purposes. It is not possible to log in and except for displaying bug reports and their history, links might be broken. See T13874, the corresponding Phabricator task for complete and up-to-date bug report information.
Bug 11874 - Enforced   breaks inline CSS with !important
Enforced   breaks inline CSS with !important
Status: RESOLVED FIXED
Product: MediaWiki
Classification: Unclassified
Parser (Other open bugs)
1.12.x
All All
: Normal normal (vote)
: ---
Assigned To: Nobody - You can work on this!
http://ru.wikipedia.org/wiki/Template...
: easy, patch, patch-need-review
Depends on:
Blocks: css
  Show dependency treegraph
 
Reported: 2007-11-05 06:48 UTC by Kalan
Modified: 2014-06-27 03:56 UTC (History)
3 users (show)

See Also:
Web browser: ---
Mobile Platform: ---
Assignee Huggle Beta Tester: ---


Attachments
proposed patch (482 bytes, patch)
2008-03-24 18:23 UTC, Nicolas Dumazet
Details

Description Kalan 2007-11-05 06:48:58 UTC
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.
Comment 1 Nicolas Dumazet 2008-03-24 18:23:48 UTC
Created attachment 4754 [details]
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.
Comment 2 Brion Vibber 2008-03-24 18:32:44 UTC
Looks good! Applied with parser test cases in r32375
Comment 3 Brion Vibber 2008-03-24 18:45:59 UTC
Slight modification in r32377 for the case where space is present between ! and important
Comment 4 Aryeh Gregor (not reading bugmail, please e-mail directly) 2008-03-24 20:03:48 UTC
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?
Comment 5 Aryeh Gregor (not reading bugmail, please e-mail directly) 2008-03-24 20:08:57 UTC
(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).
Comment 6 Brion Vibber 2008-03-24 20:17:39 UTC
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.
Comment 7 Aryeh Gregor (not reading bugmail, please e-mail directly) 2008-03-24 20:24:32 UTC
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.
Comment 8 Omegatron 2008-04-09 00:47:59 UTC
This does screw up things like style="border : solid;"  It should not apply inside HTML tags by default.
Comment 9 Mormegil 2008-11-12 22:18:16 UTC
Definitely. See bug #3158

Note You need to log in before you can comment on or make changes to this bug.


Navigation
Links