Skip to content

Commit

Permalink
Merge pull request #2416 from alexmaris/alexmaris-fix-965
Browse files Browse the repository at this point in the history
Fix forceSimpleAmpersand config implementation
  • Loading branch information
mlewand authored Sep 14, 2018
2 parents a0ba16d + 3ce574e commit 596a811
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 2 deletions.
4 changes: 3 additions & 1 deletion plugins/htmlwriter/plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -179,9 +179,11 @@ CKEDITOR.htmlWriter = CKEDITOR.tools.createClass( {
attribute: function( attName, attValue ) {

if ( typeof attValue == 'string' ) {
this.forceSimpleAmpersand && ( attValue = attValue.replace( /&/g, '&' ) );
// Browsers don't always escape special character in attribute values. (http://dev.ckeditor.com/ticket/4683, http://dev.ckeditor.com/ticket/4719).
attValue = CKEDITOR.tools.htmlEncodeAttr( attValue );

// Run ampersand replacement after the htmlEncodeAttr, otherwise the results are overwritten (https://github.com/ckeditor/ckeditor-dev/issues/965)
this.forceSimpleAmpersand && ( attValue = attValue.replace( /&/g, '&' ) );
}

this._.output.push( ' ', attName, '="', attValue, '"' );
Expand Down
36 changes: 35 additions & 1 deletion tests/plugins/htmlwriter/htmlwriter.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,5 +39,39 @@ bender.test( {
assert.areSame( afterFormat, bot.getData( false, false ) );
} );
} );
},
'test editor config.forceSimpleAmpersand in html element attributes': function () {
var data = '<p><a href="http://www.blah.com?foo=1&bar=2">Test link</a></p>';
bender.editorBot.create({
name: 'basic_forceSimpleAmpersand',
formattedOutput: true,

config: {
allowedContent: true,
forceSimpleAmpersand: true,

on: {
instanceReady: function (evt) {
var wrtierConfig = {
indent: true,
breakBeforeOpen: false,
breakAfterOpen: false,
breakBeforeClose: false,
breakAfterClose: false
};

evt.editor.dataProcessor.writer.setRules('p', wrtierConfig);
evt.editor.dataProcessor.writer.setRules('div', wrtierConfig);
}
}
}
}, function (bot) {
bot.setData( data, function () {
var afterFormat = bot.getData( false, false);

// Trigger getData a second time to reveal bug.
assert.areSame( afterFormat, data);
});
});
}
} );
} );

0 comments on commit 596a811

Please sign in to comment.