Skip to content

Commit a2f41b7

Browse files
committed
Fixed issue kindsoft#324 in googlecode: noscript bug
1 parent 53f7573 commit a2f41b7

7 files changed

Lines changed: 101 additions & 69 deletions

File tree

changelog.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ ver 4.1
1313
* Bugfix: FF、Chrome、Opera等行首全角空格被过滤,只有IE没问题。
1414
* Bugfix: 图片正在上传时,连续点击确定按钮,会重复提交表单。
1515
* Bugfix: [WEBKIT] BR换行需要两次回车才能换行。
16+
* Bugfix: noscript里的HTML代码会被转移字符。
1617

1718
ver 4.0.6 (2012-03-18)
1819
* 新增: imageTabIndex初始化参数,可设置插入图片弹出层的默认显示标签。

kindeditor-min.js

Lines changed: 65 additions & 64 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

kindeditor.js

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3475,6 +3475,7 @@ function _getInitHtml(themesPath, bodyClass, cssPath, cssData) {
34753475
'p {margin:5px 0;}',
34763476
'table {border-collapse:collapse;}',
34773477
'img {border:0;}',
3478+
'noscript {display:none;}',
34783479
'table.ke-zeroborder td {border:1px dotted #AAA;}',
34793480
'img.ke-flash {',
34803481
' border:1px solid #AAA;',
@@ -3505,7 +3506,7 @@ function _getInitHtml(themesPath, bodyClass, cssPath, cssData) {
35053506
' width:16px;',
35063507
' height:16px;',
35073508
'}',
3508-
'.ke-script {',
3509+
'.ke-script, .ke-noscript {',
35093510
' display:none;',
35103511
' font-size:0;',
35113512
' width:0;',
@@ -5669,7 +5670,10 @@ _plugin('core', function(K) {
56695670
});
56705671
});
56715672
self.beforeGetHtml(function(html) {
5672-
return html.replace(/<img[^>]*class="?ke-(flash|rm|media)"?[^>]*>/ig, function(full) {
5673+
return html.replace(/(<(?:noscript|noscript\s[^>]*)>)([\s\S]*?)(<\/noscript>)/ig, function($0, $1, $2, $3) {
5674+
return $1 + _unescape($2).replace(/\s+/g, ' ') + $3;
5675+
})
5676+
.replace(/<img[^>]*class="?ke-(flash|rm|media)"?[^>]*>/ig, function(full) {
56735677
var imgAttrs = _getAttrList(full),
56745678
styles = _getCssList(imgAttrs.style || ''),
56755679
attrs = _mediaAttrs(imgAttrs['data-ke-tag']);
@@ -5684,6 +5688,9 @@ _plugin('core', function(K) {
56845688
.replace(/<div\s+[^>]*data-ke-script-attr="([^"]*)"[^>]*>([\s\S]*?)<\/div>/ig, function(full, attr, code) {
56855689
return '<script' + unescape(attr) + '>' + unescape(code) + '</script>';
56865690
})
5691+
.replace(/<div\s+[^>]*data-ke-noscript-attr="([^"]*)"[^>]*>([\s\S]*?)<\/div>/ig, function(full, attr, code) {
5692+
return '<noscript' + unescape(attr) + '>' + unescape(code) + '</noscript>';
5693+
})
56875694
.replace(/(<[^>]*)data-ke-src="([^"]*)"([^>]*>)/ig, function(full, start, src, end) {
56885695
full = full.replace(/(\s+(?:href|src)=")[^"]*(")/i, '$1' + src + '$2');
56895696
full = full.replace(/\s+data-ke-src="[^"]*"/i, '');
@@ -5711,6 +5718,9 @@ _plugin('core', function(K) {
57115718
.replace(/<script([^>]*)>([\s\S]*?)<\/script>/ig, function(full, attr, code) {
57125719
return '<div class="ke-script" data-ke-script-attr="' + escape(attr) + '">' + escape(code) + '</div>';
57135720
})
5721+
.replace(/<noscript([^>]*)>([\s\S]*?)<\/noscript>/ig, function(full, attr, code) {
5722+
return '<div class="ke-noscript" data-ke-noscript-attr="' + escape(attr) + '">' + escape(code) + '</div>';
5723+
})
57145724
.replace(/(<[^>]*)(href|src)="([^"]*)"([^>]*>)/ig, function(full, start, key, src, end) {
57155725
if (full.match(/\sdata-ke-src="[^"]*"/i)) {
57165726
return full;

src/edit.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ function _getInitHtml(themesPath, bodyClass, cssPath, cssData) {
2121
'p {margin:5px 0;}',
2222
'table {border-collapse:collapse;}',
2323
'img {border:0;}',
24+
'noscript {display:none;}',
2425
'table.ke-zeroborder td {border:1px dotted #AAA;}',
2526
'img.ke-flash {',
2627
' border:1px solid #AAA;',
@@ -51,7 +52,7 @@ function _getInitHtml(themesPath, bodyClass, cssPath, cssData) {
5152
' width:16px;',
5253
' height:16px;',
5354
'}',
54-
'.ke-script {',
55+
'.ke-script, .ke-noscript {',
5556
' display:none;',
5657
' font-size:0;',
5758
' width:0;',

src/main.js

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1406,7 +1406,10 @@ _plugin('core', function(K) {
14061406
});
14071407
// 取得HTML前执行
14081408
self.beforeGetHtml(function(html) {
1409-
return html.replace(/<img[^>]*class="?ke-(flash|rm|media)"?[^>]*>/ig, function(full) {
1409+
return html.replace(/(<(?:noscript|noscript\s[^>]*)>)([\s\S]*?)(<\/noscript>)/ig, function($0, $1, $2, $3) {
1410+
return $1 + _unescape($2).replace(/\s+/g, ' ') + $3;
1411+
})
1412+
.replace(/<img[^>]*class="?ke-(flash|rm|media)"?[^>]*>/ig, function(full) {
14101413
var imgAttrs = _getAttrList(full),
14111414
styles = _getCssList(imgAttrs.style || ''),
14121415
attrs = _mediaAttrs(imgAttrs['data-ke-tag']);
@@ -1421,6 +1424,9 @@ _plugin('core', function(K) {
14211424
.replace(/<div\s+[^>]*data-ke-script-attr="([^"]*)"[^>]*>([\s\S]*?)<\/div>/ig, function(full, attr, code) {
14221425
return '<script' + unescape(attr) + '>' + unescape(code) + '</script>';
14231426
})
1427+
.replace(/<div\s+[^>]*data-ke-noscript-attr="([^"]*)"[^>]*>([\s\S]*?)<\/div>/ig, function(full, attr, code) {
1428+
return '<noscript' + unescape(attr) + '>' + unescape(code) + '</noscript>';
1429+
})
14241430
.replace(/(<[^>]*)data-ke-src="([^"]*)"([^>]*>)/ig, function(full, start, src, end) {
14251431
full = full.replace(/(\s+(?:href|src)=")[^"]*(")/i, '$1' + src + '$2');
14261432
full = full.replace(/\s+data-ke-src="[^"]*"/i, '');
@@ -1449,6 +1455,9 @@ _plugin('core', function(K) {
14491455
.replace(/<script([^>]*)>([\s\S]*?)<\/script>/ig, function(full, attr, code) {
14501456
return '<div class="ke-script" data-ke-script-attr="' + escape(attr) + '">' + escape(code) + '</div>';
14511457
})
1458+
.replace(/<noscript([^>]*)>([\s\S]*?)<\/noscript>/ig, function(full, attr, code) {
1459+
return '<div class="ke-noscript" data-ke-noscript-attr="' + escape(attr) + '">' + escape(code) + '</div>';
1460+
})
14521461
.replace(/(<[^>]*)(href|src)="([^"]*)"([^>]*>)/ig, function(full, start, key, src, end) {
14531462
if (full.match(/\sdata-ke-src="[^"]*"/i)) {
14541463
return full;

test/editor.html

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,9 @@ <h2 id="qunit-userAgent"></h2>
5050
<br />
5151
<br />
5252
<textarea id="content1" name="content1" style="width:90%;height:250px;visibility:hidden;"></textarea>
53-
53+
<br />
54+
<textarea id="content2" name="content2" style="width:90%;height:250px;visibility:hidden;"></textarea>
55+
<br />
5456
<!-- include test files -->
5557
<script src="editor.js"></script>
5658
</body>

test/editor.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,14 @@ KindEditor.ready(function (K) {
77
wellFormatMode : false
88
});
99

10+
var editor2 = K.create('#content2', {
11+
basePath : '../',
12+
wellFormatMode : false
13+
});
14+
1015
test("K.instances", function() {
1116
ok(editor == K.instances[0]);
17+
ok(editor2 == K.instances[1]);
1218
});
1319

1420
test("editor.html", function() {
@@ -22,6 +28,8 @@ KindEditor.ready(function (K) {
2228
equals(editor.html(), '<div class="aaa bbb ccc">abc</div>');
2329
editor.html('<p> abc</p>');
2430
equals(editor.html(), '<p> abc</p>');
31+
editor.html('<noscript><img src="" /></noscript>');
32+
equals(editor.html(), '<noscript><img src="" /></noscript>');
2533
});
2634

2735
test("editor.text", function() {

0 commit comments

Comments
 (0)