Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit6bc6a45

Browse files
committed
fixup! Core:Manipulation: Add basic TrustedHTML support
1 parente3165e6 commit6bc6a45

File tree

2 files changed

+44
-34
lines changed

2 files changed

+44
-34
lines changed

‎test/data/trusted-html.html

Lines changed: 40 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -9,22 +9,8 @@
99
<scriptsrc="../../dist/jquery.min.js"></script>
1010
<scriptsrc="iframeTest.js"></script>
1111
<script>
12-
if(typeoftrustedTypes==="undefined"){
13-
startIframeTest([{
14-
actual:"",
15-
expected:"trustedTypes support",
16-
message:"trustedTypes supported"
17-
}]);
18-
thrownewError("No trustedTypes support; this test should be skipped");
19-
}
20-
21-
vari,input,elem,tags,
12+
vari,input,elem,tags,policy,
2213
results=[],
23-
policy=trustedTypes.createPolicy("jquery-test-policy",{
24-
createHTML:function(html){
25-
returnhtml;
26-
}
27-
}),
2814
inputs=[
2915
["<div></div>","<div class='test'></div>",["div"]],
3016
["<div></div>","<div class='test'></div><span class='test'></span>",
@@ -33,27 +19,49 @@
3319
["<select></select>","<option class='test'></option>",["option"]]
3420
];
3521

36-
for(i=0;i<inputs.length;i++){
37-
input=inputs[i];
38-
elem=jQuery(policy.createHTML(input[0]));
39-
elem.append(policy.createHTML(input[1]));
40-
tags=elem.find(".test").toArray().map(function(node){
41-
returnnode.nodeName.toLowerCase();
42-
});
22+
functionrunTests(messagePrefix,getHtmlWrapper){
23+
for(i=0;i<inputs.length;i++){
24+
input=inputs[i];
25+
elem=jQuery(getHtmlWrapper(input[0]));
26+
elem.append(getHtmlWrapper(input[1]));
27+
tags=elem.find(".test").toArray().map(function(node){
28+
returnnode.nodeName.toLowerCase();
29+
});
30+
results.push({
31+
actual:tags,
32+
expected:input[2],
33+
message:messagePrefix+": "+input[2].join(", ")
34+
});
35+
}
36+
37+
elem=jQuery(getHtmlWrapper("<div></div>"));
38+
elem.append(getHtmlWrapper("text content"));
4339
results.push({
44-
actual:tags,
45-
expected:input[2],
46-
message:input[2].join(", ")
40+
actual:elem.html(),
41+
expected:"text content",
42+
message:messagePrefix+": text content properly appended"
4743
});
4844
}
4945

50-
elem=jQuery(policy.createHTML("<div></div>"));
51-
elem.append(policy.createHTML("text content"));
52-
results.push({
53-
actual:elem.html(),
54-
expected:"text content",
55-
message:"Text content properly appended"
56-
});
46+
if(typeoftrustedTypes!=="undefined"){
47+
policy=trustedTypes.createPolicy("jquery-test-policy",{
48+
createHTML:function(html){
49+
returnhtml;
50+
}
51+
});
52+
53+
runTests("TrustedHTML",functionwrapInTrustedHtml(input){
54+
returnpolicy.createHTML(input);
55+
});
56+
}else{
57+
runTests("Object wrapper",function(input){
58+
return{
59+
toString:functiontoString(){
60+
returninput;
61+
}
62+
};
63+
});
64+
}
5765

5866
startIframeTest(results);
5967
</script>

‎test/unit/manipulation.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3010,15 +3010,17 @@ QUnit.test( "Works with invalid attempts to close the table wrapper", function(
30103010
});
30113011

30123012
// Test trustedTypes support in browsers where they're supported (currently Chrome 83+).
3013+
// Browsers with no TrustedHTML support still run tests on object wrappers with
3014+
// a proper `toString` function.
30133015
testIframe(
30143016
"Basic TrustedHTML support (gh-4409)",
30153017
"mock.php?action=trustedHtml",
30163018
function(assert,jQuery,window,document,test){
3019+
30173020
assert.expect(5);
30183021

30193022
test.forEach(function(result){
30203023
assert.deepEqual(result.actual,result.expected,result.message);
30213024
});
3022-
},
3023-
typeoftrustedTypes==="undefined" ?QUnit.skip :QUnit.test
3025+
}
30243026
);

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp