You are here: Foswiki>Tasks Web>Item13182 (05 Jul 2015, GeorgeClark)Edit Attach

Item13182: FW doesn't ignore ! within style tags

Priority: Urgent
Current State: Closed
Released In: 2.0.0
Target Release: major
Applies To: Engine
Component: FoswikiRender
Branches: master
Reported By: VickiBrown
Waiting For:
Last Change By: GeorgeClark
Refer also to: Item13143: CSS cell coloring code works as expected in TWIki, fails in Foswiki

I added this CSS to one of my pages:

<style type="text/css">
.cell_red { background-color: #f44 !important; }
.cell_yellow { background-color: #ff4 !important; }
.cell_green { background-color: #4f4 !important; }

The colors did not work and the Error console told me my CSS code was invalid.

The reason for the error is that Foswiki saw, handled, and stripped the ! character in !important.

The workaround is to use

<style type="text/css">
.cell_red { background-color: #f44!important; }
.cell_yellow { background-color: #ff4!important; }
.cell_green { background-color: #4f4!important; }

However, this is not required by CSS syntax and violates the Principle of Least Surprise.

Foswiki should ignore a ! within style tags. (Foswiki should probably ignore pretty much everything within style or script tags.)

-- VickiBrown - 30 Dec 2014

Not sure how to fix this, but the cause is wholesale replace of ! escapes to &lt/nop> tags throughout the topic, and then removing the <nop> tags at the end of the rendering function:

    # Escape rendering: Change ' !AnyWord' to ' <nop>AnyWord',
    # for final ' AnyWord' output
    $text =~ s/$STARTWW\!(?=[\w\*\=])/<nop>/gm;

This (excessive escaping) is actually a broader and very longstanding issue. See Item252 and Item10242.

For <style> blocks we could probably take out (protect) the style blocks at start of rendering, and put them back at the end, like we do with verbatims, html comments, etc. But I'm reluctant to do this, as the render engine is pretty complex.

Another thing we could do is instead of matching for \w "word characters", we could look for uppercase alpha when converting ! to <nop>. But all that said, touching render is rather dangerous.

-- GeorgeClark - 04 Jan 2015

Setting this to urgent because this excessive escaping needs some review for 1.2.

-- GeorgeClark - 04 Jan 2015
Topic revision: r4 - 05 Jul 2015, GeorgeClark - This page was cached on 03 Jun 2017 - 08:45.

The copyright of the content on this website is held by the contributing authors, except where stated elsewhere. See Copyright Statement. Creative Commons License