Last modified: 2011-04-14 15:10:34 UTC

Wikimedia Bugzilla is closed!

Wikimedia has migrated from Bugzilla to Phabricator. Bug reports should be created and updated in Wikimedia Phabricator instead. Please create an account in Phabricator and add your Bugzilla email address to it.
Wikimedia Bugzilla is read-only. If you try to edit or create any bug report in Bugzilla you will be shown an intentional error message.
In order to access the Phabricator task corresponding to a Bugzilla report, just remove "static-" from its URL.
You could still run searches in Bugzilla or access your list of votes but bug reports will obviously not be up-to-date in Bugzilla.
Bug 24662 - escaping whitespaces in style-attributes
escaping whitespaces in style-attributes
Status: NEW
Product: MediaWiki
Classification: Unclassified
Parser (Other open bugs)
unspecified
All All
: Low normal with 2 votes (vote)
: ---
Assigned To: Nobody - You can work on this!
:
Depends on:
Blocks:
  Show dependency treegraph
 
Reported: 2010-08-04 13:08 UTC by Bergi
Modified: 2011-04-14 15:10 UTC (History)
1 user (show)

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


Attachments

Description Bergi 2010-08-04 13:08:03 UTC
Some browsers dont like it when there are unusual whitespaces in the style-attribute of an HTML-tag (means: they cant display the CSS in the correct way). This causes some template errors like [http://de.wikipedia.org/wiki/Wikipedia:WikiProjekt_Vorlagen/Werkstatt#commons:Template:Bar_box_und_commons:Template:Bar_pixel here]. The template uses unnamed parameters in its style-attributes, and an include whith one line per parameter causes that the line break can still be found in the HTML source code.
You can solve the Problem by using ParserFunctions in the template like 
 style="background:{{#if:TRUE|{{{1|none}}}}};"
but that is not as good as doing this by the parser also. This could be done by an regularExpression like that:
 replace(/[\s\n\r\t]+, " "); //I'm not an expert
Also   and Co are not likely seen by some browsers.
Comment 1 Thana 2010-08-12 02:54:29 UTC
if this is about color properties within the style attribute being
interpreted as the start of an ordered list (on account of they both
begin with "#") this is another duplicate of bug 12974.

> an regularExpression like that:
> replace(/[\s\n\r\t]+, " "); //I'm not an expert
> Also   and Co are not likely seen by some browsers.

you mean use this: http://php.net/manual/en/function.trim.php

\s by itself means all the above, just so you know.
exposing trim as a parser-function wouldn't be a bad idea either.
Comment 2 Bergi 2010-08-14 09:51:23 UTC
> if this is about color properties within the style attribute being
> interpreted as the start of an ordered list (on account of they both
> begin with "#") this is another duplicate of bug 12974.

No, its about every property. Of course it could help with the color problem if the replace is executed before the rendering to lists, but bug 12974 is about all functions that begin with "{{" and not only in the style attribute.

> > an regularExpression like that:
> > replace(/[\s\n\r\t]+, " "); //I'm not an expert
> 
> you mean use this: http://php.net/manual/en/function.trim.php

No, trim just does it in the beginning and end of a string. I would like to use http://www.php.net/manual/en/function.preg-replace.php for every whitespace _in_ the string, between style properties and their values, wihin the values and among the diverse properties.

> exposing trim as a parser-function wouldn't be a bad idea either.

You can already use {{#if:true|  <many blanks>   }}, and the returned value (also works with ifeq, ifexpr and switch) is automatically trimmed.

> \s by itself means all the above, just so you know.

Thanks, Im never sure. Better to much than to less...
Comment 3 Thana 2010-08-15 19:37:00 UTC
the mw parser already replaces consecutive spaces by a single space:
> <span style="font-size:        larger;">HELLO       1</span>
outputs cleanly as:
> <span style="font-size: larger;">HELLO 1</span>

however it does not remove single undesired interior spaces, including
those before the colon and semi-colon in the following:
> <span style=" border : 1px solid red ; ">HELLO 2</span>

either of which cause the parser to reject the above as a malformed css
property, rather than attempting to clean it up. the outputted html is
in fact:
> <span style="">HELLO 2</span>

no use of the php trim feature or of a tautological parser function as in
your example would prevent this invalidation if the spaces are not at the
beginning or end of user input.

i suppose you could have the parser do some tidying like this inside the
aggregate style attribute (carefully to avoid removing needful spaces as
within "1px solid red"):
> $style = preg_replace('/\s*(^|[\:\;]|$)\s*/g', '\\1', $style);

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


Navigation
Links