Opened 7 years ago

Closed 7 years ago

#5128 closed Bug (fixed)

Text content of <pre> element with attributes is removed when changing the formatting

Reported by: Razvan Caliman Owned by: Garry Yao
Priority: Normal Milestone: CKEditor 3.3
Component: Core : Styles Version: 3.0 Beta
Keywords: Confirmed Review+ Cc:

Description

When trying to alter the formatting of a <pre> block that has attributes (like "class", "style", etc.) the text is removed from the editor.

Steps to reproduce:

  1. Go to CKeditor and switch to "Source" mode
  2. Paste <pre style="color: green">This is a bug.</pre>
  3. Switch back to "WYSIWYG" mode
  4. Select the text "This is a bug"
  5. Click the formatting dropdown and select "Heading 1"

Result:
The text is removed from the editor.

Expected:
The text should change to new formatting and not be removed.

Bug cause & solution:
The issue comes from a regular expression that doesn't check for attributes of <pre> elements. It is found in CKEditor's styles plugin.

file: _source/plugins/styles/plugin.js
line: 770
method: splitIntoPres()

problem:
splitedHtml.replace( /<pre>([\s\S]*?)<\/pre>/gi, ...

solution:
splitedHtml.replace( /<pre[\s\S]*?>([\s\S]*?)<\/pre>/gi ...

Attachments (1)

5128.patch (514 bytes) - added by Garry Yao 7 years ago.

Download all attachments as: .zip

Change History (6)

comment:1 Changed 7 years ago by Alfonso Martínez de Lizarrondo

Keywords: HasPatch added

comment:2 Changed 7 years ago by Frederico Caldeira Knabben

Milestone: CKEditor 3.3

Changed 7 years ago by Garry Yao

Attachment: 5128.patch added

comment:3 Changed 7 years ago by Garry Yao

Keywords: Confirmed Review? added; HasPatch removed
Owner: set to Garry Yao
Status: newassigned

Thanks rcaliman for the bug report and the patch.
This should have been fixed earlier.

comment:4 Changed 7 years ago by Alfonso Martínez de Lizarrondo

Keywords: Review+ added; Review? removed

comment:5 Changed 7 years ago by Garry Yao

Resolution: fixed
Status: assignedclosed

Fixed with [5257].

Note: See TracTickets for help on using tickets.
© 2003 – 2017 CKSource – Frederico Knabben. All rights reserved. | Terms of use | Privacy policy