#292 fck_paste CleanWord() eats <br></b> tags (patch)

closed-fixed
Editor (144)
5
2006-08-28
2006-08-28
Anonymous
No

The "Paste-from-word cleanup" javascript regex marathon
in fck_paste.html has a slight bug which turns html
containing things like "123<br></b>456" into "123456".

I've seen this happening with many word documents where
there is a bolded header, a linebreak and then a
regular paragraph following immediately - the result is
that the linebreak is removed and the bold tag is not
closed.

The fix is simple (diff against FCKEditor 2.3.1):
--- fck_paste.html.orig 2006-08-28 11:12:57.000000000 +0200
+++ fck_paste.html 2006-08-28 11:14:16.000000000 +0200
@@ -164,9 +164,9 @@
html = html.replace(
/<(U|I|STRIKE)>&nbsp;<\/\1>/g, '&nbsp;' ) ;

// Remove empty tags (three times, just to be
sure).
- html = html.replace(
/<([^\s>]+)[^>]*>\s*<\/\1>/g, '' ) ;
- html = html.replace(
/<([^\s>]+)[^>]*>\s*<\/\1>/g, '' ) ;
- html = html.replace(
/<([^\s>]+)[^>]*>\s*<\/\1>/g, '' ) ;
+ html = html.replace(
/<([^\s>]+)(\s[^>]*)?>\s*<\/\1>/g, '' ) ;
+ html = html.replace(
/<([^\s>]+)(\s[^>]*)?>\s*<\/\1>/g, '' ) ;
+ html = html.replace(
/<([^\s>]+)(\s[^>]*)?>\s*<\/\1>/g, '' ) ;

// Transform <P> to <DIV>
var re = new
RegExp("(<P)([^>]*>.*?)(<\/P>)","gi") ; // Different
because of a IE 5.0 error

What's going on is that the original regex finds the
'b' in <br> and in </b> and assumes these are empty
tags. This happens because the second optional part of
the matcher for the opening tag - the part containing
[^>]* does not require a space prefix, so that part
matches the 'r' in '<br>', and then the \1
backreference matches the 'b' in '<br>'.

By the way, the resulting corrupt HTML (which is
lacking closing </b> tags) may cause futher problems
down the road when the editor contents is saved through
FCKXhtml.GetXHTML since the IE DOM walking code returns
very unexpected results. I'll probably post another bug
report for that later.

- frode@coretrek.com

Discussion

  • Frederico Caldeira Knabben

    • assigned_to: nobody --> fredck
    • status: open --> closed-fixed
     
  • Frederico Caldeira Knabben

    Logged In: YES
    user_id=572424

    Hi,

    This patch, or a similar implementation, has been included in
    FCKeditor and has been committed in the SVN. It will be
    available in the next release.

    For more information about the FCKeditor SVN system, please use
    the following URL:
    http://wiki.fckeditor.net/SVN

    Best regards,
    FredCK
    http://www.fckeditor.net
    "Support Open Source Software... What about a donation today?"

    PS.: This is a canned response.

     

Log in to post a comment.

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:





No, thanks