Skip to content
This repository was archived by the owner on Oct 14, 2024. It is now read-only.

Commit 0a400bf

Browse files
Fix color conversion to hexadecimal format (Resolve #452) (#453)
1 parent a7e04b6 commit 0a400bf

File tree

3 files changed

+9
-2
lines changed

3 files changed

+9
-2
lines changed

AjaxControlToolkit.Jasmine/Suites/HtmlEditorExtenderTests/HtmlEditorExtenderTests.aspx

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -901,6 +901,13 @@
901901
var actualContentText = wrapper.currentState.editorContent();
902902
expect(actualContentText).toBe("a");
903903
});
904+
905+
it("encodes color to hex properly", function() {
906+
var wrapper = new HtmlEditorWrapper(this.extender);
907+
wrapper.setContent("<span style=\"color: rgb(0, 0, 204);\">a</span>", "source").switchTab("content");
908+
var expectedText = "&lt;span style=&quot;color: #0000cc;&quot;&gt;a&lt;/span&gt;";
909+
expect(this.extender._encodeHtml()).toBe(expectedText);
910+
});
904911
});
905912
</script>
906913

AjaxControlToolkit/Scripts/HtmlEditorExtender.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -820,7 +820,7 @@ Sys.Extended.UI.HtmlEditorExtenderBehavior.prototype = {
820820
_rgbToHex: function(s) {
821821
var a = /rgb\s?\(\s?(\d+)\s?,\s?(\d+)\s?,\s?(\d+)\s?\)/.exec(s);
822822

823-
return '#' + (parseInt(a[3], 10) | (parseInt(a[2], 10) << 8) | (parseInt(a[1], 10) << 16)).toString(16);
823+
return '#' + ("000000" + (parseInt(a[3], 10) | (parseInt(a[2], 10) << 8) | (parseInt(a[1], 10) << 16)).toString(16)).substr(-6);
824824
},
825825

826826
_encodeHtml: function() {

0 commit comments

Comments
 (0)