-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathonpaste_test.html
322 lines (306 loc) · 9.61 KB
/
onpaste_test.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta charset="utf-8">
<title>contentEditable - onpaste Test</title>
<style>
body {
font-family: verdana, arial, sans-serif;
font-size: 12px;
}
h1 {
font-size: 20px;
}
h3 {
font-size: 18px;
margin-top: 40px;
}
em {
display: block;
border: 1px solid #999;
padding: 4px;
}
.innercircle {
margin: 5px 0;
padding: 5px;
border: 1px solid #acacac;
-webkit-border-radius: 3px;
-moz-border-radius: 3px;
border-radius: 3px;
display: block;
}
#editor {
min-height: 100px;
}
td, th {
padding: 5px;
text-align: center;
}
td:first-child {
text-align: left;
}
td.yes {
background-color: rgb(0, 255, 0);
background-color: rgba(0, 255, 0, 0.5);
}
td.neutral {
background-color: rgb(255, 255, 255);
background-color: rgba(255, 255, 255, 0.5);
}
td {
background-color: rgb(255, 0, 0);
background-color: rgba(255, 0, 0, 0.5);
}
td:first-child {
background-color: transparent;
}
th {
background-color: #ccc;
}
tr:hover {
background-color: #ccc;
}
small {
font-size: 10px;
display: block;
}
</style>
<script src="https://ajax.googleapis.com/ajax/libs/prototype/1.6.1.0/prototype.js"></script>
</head>
<body>
<h1>onpaste Test</h1>
<p>This test checks whether the browser copies javascript/css elements & inline handlers into contentEditable areas</p>
<p>
Paste the <strong>entire</strong> following text into the contentEditable area below: <br>
<em>
Copy me!
<script>window._inlineScript = true;</script>
Copy me!
<img src="foo.gif" onerror="window._inlineHandler = true;" width="1" height="1">
Copy me!
<input onfocus="window._inlineAutoFocusHandler = true;" autofocus style="width:1px">
Copy me!
<script src="external_script.js"></script>
Copy me!
<iframe src="javascript:void(parent.window._iframeSrc=true);" width="1" height="1" frameborder="0"></iframe>
Copy me!
<style>.inline-test { display: none; }</style>
Copy me!
<link rel="stylesheet" type="text/css" src="external_stylesheet.css">
Copy me!
</em>
</p>
<h3>Editor</h3>
<div contenteditable="true" class="innercircle" id="editor">#</div>
<h3>Generated markup</h3>
<code id="editor-markup" class="innercircle"></code>
<h3>Compatibility Table (whether the browser adopts the javascript/css in the contentEditable area)</h3>
<table>
<tr>
<th>Type</th>
<th>Your Browser</th>
<th>IE 6</th>
<th>IE 7</th>
<th>IE 8</th>
<th>IE 9b</th>
<th>Chrome 7</th>
<th>Safari 5</th>
<th>Firefox 3.6</th>
<th>Firefox 4b</th>
<th>Opera 10.63</th>
<th>Opera 11b</th>
<th>Android 2.2 (MobileSafari)</th>
<th>iPad iOS 4.2 (MobileSafari)</th>
</tr>
<tr>
<td>
inline script<br />
<code><script>foo();</script></code>
</td>
<td id="_inlineScript" class="neutral"> </td>
<td class="yes">yes <small>(but not executed **)</small></td>
<td class="yes">yes <small>(but not executed **)</small></td>
<td class="yes">yes <small>(but not executed **)</small></td>
<td class="yes">yes <small>(but not executed **)</small></td>
<td>no</td>
<td>no</td>
<td>no</td>
<td>no</td>
<td>no</td>
<td>no</td>
<td class="neutral">untestable *</td>
<td class="neutral">untestable *</td>
</tr>
<tr>
<td>
external script<br />
<code><script src="foo.js"></script></code>
</td>
<td id="_externalScript" class="neutral"> </td>
<td class="yes">yes <small>(but not executed **)</small></td>
<td class="yes">yes <small>(but not executed **)</small></td>
<td class="yes">yes <small>(but not executed **)</small></td>
<td class="yes">yes <small>(but not executed **)</small></td>
<td>no</td>
<td>no</td>
<td>no</td>
<td>no</td>
<td>no</td>
<td>no</td>
<td class="neutral">untestable *</td>
<td class="neutral">untestable *</td>
</tr>
<tr>
<td>
inline handler<br />
<code><img src="foo.gif" onerror="foo();"></code>
</td>
<td id="_inlineHandler" class="neutral"> </td>
<td class="yes">yes</td>
<td class="yes">yes</td>
<td class="yes">yes</td>
<td>no ***</td>
<td>no</td>
<td>no</td>
<td>no</td>
<td>no</td>
<td>no</td>
<td>no</td>
<td class="neutral">untestable *</td>
<td class="neutral">untestable *</td>
</tr>
<tr>
<td>
inline autofocus handler<br />
<code><input onfocus="foo();" autofocus></code>
</td>
<td id="_inlineAutoFocusHandler" class="neutral"> </td>
<td>?</td>
<td>?</td>
<td>?</td>
<td>?</td>
<td>?</td>
<td>?</td>
<td>?</td>
<td>?</td>
<td>?</td>
<td>?</td>
<td class="neutral">untestable *</td>
<td class="neutral">untestable *</td>
</tr>
<tr>
<td>
iframe src<br />
<code><iframe src="javascript:foo();"></code>
</td>
<td id="_iframeSrc" class="neutral"> </td>
<td class="yes">yes</td>
<td class="yes">yes</td>
<td class="yes">yes</td>
<td class="yes">yes <small>(but not executed **)</small></td>
<td>no</td>
<td>no</td>
<td>no</td>
<td>no</td>
<td>no</td>
<td>no</td>
<td class="neutral">untestable *</td>
<td class="neutral">untestable *</td>
</tr>
<tr>
<td>
inline style<br />
<code><style>.foobar { foo:bar; }</style></code>
</td>
<td id="_inlineStyle" class="neutral"> </td>
<td class="yes">yes</td>
<td class="yes">yes</td>
<td class="yes">yes</td>
<td class="yes">yes</td>
<td>no</td>
<td>no</td>
<td class="yes">yes</td>
<td>no</td>
<td>no</td>
<td>no</td>
<td class="neutral">untestable *</td>
<td class="neutral">untestable *</td>
</tr>
<tr>
<td>
external style<br />
<code><link rel="stylesheet" src="foobar.css"></code>
</td>
<td id="_externalStyle" class="neutral"> </td>
<td class="yes">yes</td>
<td class="yes">yes</td>
<td class="yes">yes</td>
<td class="yes">yes</td>
<td>no</td>
<td>no</td>
<td>no</td>
<td>no</td>
<td>no</td>
<td>no</td>
<td class="neutral">untestable *</td>
<td class="neutral">untestable *</td>
</tr>
</table>
<button id="check" disabled type="button">Check your browser</button>
<p>
<small>
* Android 2.2 and iOS 4.2 don't correctly support contentEditable elements<br>
** The browser adopts the javascript into the contentEditable area but doesn't execute it<br>
*** IE9 adopts the inline handler when it's been pasted from the same origin
</small>
</p>
<script>
Event.observe(window, "load", function() {
var tests = {
"_inlineScript": "script:not([src])",
"_externalScript": "script[src]",
"_inlineHandler": "img[onerror^='window.']",
"_inlineAutoFocusHandler": "input[onfocus^='window.']",
"_iframeSrc": "iframe[src^='javascript:']",
"_inlineStyle": "style",
"_externalStyle": "link"
};
Object.keys(tests).each(function(test) { window[test] = false; });
var editor = $("editor"),
editorMarkup = $("editor-markup"),
button = $("check");
editor.focus();
button.observe("click", function() {
// Check whether js/css is adopted
$H(tests).each(function(pair) {
var isStyle = pair.key.endsWith("Style");
if (window[pair.key] && !isStyle) {
// yes, executed
$(pair.key).removeClassName("neutral").addClassName("yes").update("yes");
} else {
if (editor.down(pair.value)) {
// yes, but not executed, only adopted
$(pair.key).removeClassName("neutral").addClassName("yes").update("yes" + (isStyle ? "" : " <small>but not executed **</small>"));
} else {
// nope
$(pair.key).removeClassName("neutral").update("no");
}
}
});
});
setInterval(function() {
var escapedHtml = editor.innerHTML.escapeHTML();
if (escapedHtml != editorMarkup.innerHTML) {
editorMarkup.innerHTML = escapedHtml;
}
if (escapedHtml.length > 20) {
button.removeAttribute("disabled");
} else {
button.writeAttribute("disabled", "disabled");
}
}, 500);
});
</script>
</body>
</html>