Opened 8 years ago

Closed 6 years ago

#1298 closed defect (fixed)

CSS styling gets inserted into table cell after viewing source (Safari only)

Reported by: nicholasbs Owned by:
Priority: normal Milestone: 0.96
Component: Browsers_Firefox Version: trunk
Severity: normal Keywords:


To reproduce:

  1. Click "Insert Table" and then click "OK" to insert a table.
  2. Click in one of the table's cells.
  3. Click "Toggle HTML Source" twice.

There will now be CSS styling information in place of one of the cells. This happens in Safari 3.1.2, but not in IE7 or FF3.

Change History (4)

comment:1 Changed 8 years ago by nicholasbs

I've looked into this issue and think I found the source of the problem. There's a regex in the setCC function that seems off to me. Line 745 in Webkit.js currently reads:

ta.value = ta.value.replace(new RegExp ('(&[^'+cc+']*?)('+cc+')([^'+cc+']*?;)'), "$1$3$2");

I believe this regex is supposed to move the control character outside of an HTML character entity (e.g.,  ). However, the regex is too liberal, as it will greedily keep going past the control character. E.g., it will match

&amp;<a style="color: red;" href="">foo</a>

all the way to the semicolon after 'red', assuming of course that the cursor (and thus the control character) is placed between the ampersand and the opening angle bracket. This is a simplified case of the issue reported above, since placing the cursor in the table cell means setting the control character just after a &nbsp;.

The solution is to simply not match internal semicolons, changing the regex to:

ta.value = ta.value.replace(new RegExp ('(&[^'+cc+';]*?)('+cc+')([^'+cc+']*?;)'), "$1$3$2");

What I'm confused by is that even though their respective modules use the same regex, neither Firefox nor IE are affected by this bug. Anyone know why this might be? I've diff'd the version of setCC and findCC in Gecko.js and WebKit.js, and they're practically identical.

comment:2 Changed 8 years ago by nicholasbs

  • Resolution set to fixed
  • Status changed from new to closed

I've checked this change in for WebKit?.js as r1146.

I have not yet made the same change to the identical regexes for the Gecko and IE modules, since I would like to first figure out why it is that neither of them suffer from this same problem even though they have the same faulty regex.

comment:3 Changed 6 years ago by wymsy

  • Component changed from Browsers_Safari to Browsers_Firefox
  • Resolution fixed deleted
  • Status changed from closed to reopened

Recent versions of Firefox do in fact exhibit the problem, and a quick check of IE also shows some signs of it. I will apply Nicholas' fix to these modules, and also Opera (which I have not checked but at the least I don't see how it could hurt anything).

comment:4 Changed 6 years ago by wymsy

  • Resolution set to fixed
  • Status changed from reopened to closed

Changeset [1312].

Note: See TracTickets for help on using tickets.