Skip to content
This repository was archived by the owner on Mar 20, 2021. It is now read-only.

Commit 3466d82

Browse files
committed
Fix #4340 Script resources in <body> are never run during Ajax requests
1 parent cf2390f commit 3466d82

File tree

5 files changed

+205
-5
lines changed

5 files changed

+205
-5
lines changed

impl/src/main/js/jsf.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -818,7 +818,7 @@ if (!((jsf && jsf.specversion && jsf.specversion >= 23000 ) &&
818818
// Get scripts from text
819819
scripts = stripScripts(src);
820820
// Remove scripts from text
821-
src = src.replace(/<script[^>]*type="text\/javascript"*>([\S\s]*?)<\/script>/igm,"");
821+
src = src.replace(/<script[^>]*type="text\/javascript"[^>]*>([\S\s]*?)<\/script>/igm,"");
822822
temp.innerHTML = src;
823823
}
824824
}
@@ -1494,7 +1494,7 @@ if (!((jsf && jsf.specversion && jsf.specversion >= 23000 ) &&
14941494
// Get scripts from text
14951495
scripts = stripScripts(src);
14961496
// Remove scripts from text
1497-
newsrc = src.replace(/<script[^>]*type="text\/javascript"*>([\S\s]*?)<\/script>/igm, "");
1497+
newsrc = src.replace(/<script[^>]*type="text\/javascript"[^>]*>([\S\s]*?)<\/script>/igm, "");
14981498
elementReplace(getBodyElement(newsrc), docBody);
14991499
runScripts(scripts);
15001500
} catch (e) {
@@ -1557,7 +1557,7 @@ if (!((jsf && jsf.specversion && jsf.specversion >= 23000 ) &&
15571557
// Get the scripts from the text
15581558
scripts = stripScripts(html);
15591559
// Remove scripts from text
1560-
html = html.replace(/<script[^>]*type="text\/javascript"*>([\S\s]*?)<\/script>/igm,"");
1560+
html = html.replace(/<script[^>]*type="text\/javascript"[^>]*>([\S\s]*?)<\/script>/igm,"");
15611561
parserElement.innerHTML = '<table>' + html + '</table>';
15621562
}
15631563
var newElement = parserElement.firstChild;
@@ -1585,7 +1585,7 @@ if (!((jsf && jsf.specversion && jsf.specversion >= 23000 ) &&
15851585
// Get the scripts from the text
15861586
scripts = stripScripts(html);
15871587
// Remove scripts from text
1588-
html = html.replace(/<script[^>]*type="text\/javascript"*>([\S\s]*?)<\/script>/igm,"");
1588+
html = html.replace(/<script[^>]*type="text\/javascript"[^>]*>([\S\s]*?)<\/script>/igm,"");
15891589
parserElement.innerHTML = html;
15901590
}
15911591
replaceNode(parserElement.firstChild, element);
@@ -1623,7 +1623,7 @@ if (!((jsf && jsf.specversion && jsf.specversion >= 23000 ) &&
16231623
// Get the scripts from the text
16241624
scripts = stripScripts(html);
16251625
// Remove scripts from text
1626-
html = html.replace(/<script[^>]*type="text\/javascript"*>([\S\s]*?)<\/script>/igm,"");
1626+
html = html.replace(/<script[^>]*type="text\/javascript"[^>]*>([\S\s]*?)<\/script>/igm,"");
16271627
}
16281628
var tempElement = document.createElement('div');
16291629
var newElement = null;
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
<!--
2+
3+
DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
4+
5+
Copyright (c) 1997-2017 Oracle and/or its affiliates. All rights reserved.
6+
7+
The contents of this file are subject to the terms of either the GNU
8+
General Public License Version 2 only ("GPL") or the Common Development
9+
and Distribution License("CDDL") (collectively, the "License"). You
10+
may not use this file except in compliance with the License. You can
11+
obtain a copy of the License at
12+
https://glassfish.dev.java.net/public/CDDL+GPL_1_1.html
13+
or packager/legal/LICENSE.txt. See the License for the specific
14+
language governing permissions and limitations under the License.
15+
16+
When distributing the software, include this License Header Notice in each
17+
file and include the License file at packager/legal/LICENSE.txt.
18+
19+
GPL Classpath Exception:
20+
Oracle designates this particular file as subject to the "Classpath"
21+
exception as provided by Oracle in the GPL Version 2 section of the License
22+
file that accompanied this code.
23+
24+
Modifications:
25+
If applicable, add the following below the License Header, with the fields
26+
enclosed by brackets [] replaced by your own identifying information:
27+
"Portions Copyright [year] [name of copyright owner]"
28+
29+
Contributor(s):
30+
If you wish your version of this file to be governed by only the CDDL or
31+
only the GPL Version 2, indicate your decision by adding "[Contributor]
32+
elects to include this software in this distribution under the [CDDL or GPL
33+
Version 2] license." If you don't indicate a single choice of license, a
34+
recipient has the option to distribute your version of this file under
35+
either the CDDL, the GPL Version 2 or to extend the choice of license to
36+
its licensees as provided above. However, if you add GPL Version 2 code
37+
and therefore, elected the GPL Version 2 license, then the option applies
38+
only if the new code is made subject to such option by the copyright
39+
holder.
40+
41+
-->
42+
43+
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
44+
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
45+
<html xmlns="http://www.w3.org/1999/xhtml"
46+
xmlns:h="http://xmlns.jcp.org/jsf/html">
47+
48+
<h:head />
49+
<h:body>
50+
<h:outputScript name="issue4340.js" />
51+
</h:body>
52+
</html>
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
<!--
2+
3+
DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
4+
5+
Copyright (c) 1997-2017 Oracle and/or its affiliates. All rights reserved.
6+
7+
The contents of this file are subject to the terms of either the GNU
8+
General Public License Version 2 only ("GPL") or the Common Development
9+
and Distribution License("CDDL") (collectively, the "License"). You
10+
may not use this file except in compliance with the License. You can
11+
obtain a copy of the License at
12+
https://glassfish.dev.java.net/public/CDDL+GPL_1_1.html
13+
or packager/legal/LICENSE.txt. See the License for the specific
14+
language governing permissions and limitations under the License.
15+
16+
When distributing the software, include this License Header Notice in each
17+
file and include the License file at packager/legal/LICENSE.txt.
18+
19+
GPL Classpath Exception:
20+
Oracle designates this particular file as subject to the "Classpath"
21+
exception as provided by Oracle in the GPL Version 2 section of the License
22+
file that accompanied this code.
23+
24+
Modifications:
25+
If applicable, add the following below the License Header, with the fields
26+
enclosed by brackets [] replaced by your own identifying information:
27+
"Portions Copyright [year] [name of copyright owner]"
28+
29+
Contributor(s):
30+
If you wish your version of this file to be governed by only the CDDL or
31+
only the GPL Version 2, indicate your decision by adding "[Contributor]
32+
elects to include this software in this distribution under the [CDDL or GPL
33+
Version 2] license." If you don't indicate a single choice of license, a
34+
recipient has the option to distribute your version of this file under
35+
either the CDDL, the GPL Version 2 or to extend the choice of license to
36+
its licensees as provided above. However, if you add GPL Version 2 code
37+
and therefore, elected the GPL Version 2 license, then the option applies
38+
only if the new code is made subject to such option by the copyright
39+
holder.
40+
41+
-->
42+
43+
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
44+
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
45+
<html xmlns="http://www.w3.org/1999/xhtml"
46+
xmlns:h="http://xmlns.jcp.org/jsf/html"
47+
xmlns:f="http://xmlns.jcp.org/jsf/core">
48+
<h:head/>
49+
<h:body>
50+
<h:form id="form">
51+
<h:commandButton id="issue4340Button" value="issue4340result.xhtml" action="issue4340result.xhtml">
52+
<f:ajax render="@all" />
53+
</h:commandButton>
54+
</h:form>
55+
</h:body>
56+
</html>
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
document.getElementsByTagName('body')[0].innerHTML +=
2+
'<div id="issue4340Result">SUCCESS</div>';
Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
/*
2+
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3+
*
4+
* Copyright (c) 1997-2017 Oracle and/or its affiliates. All rights reserved.
5+
*
6+
* The contents of this file are subject to the terms of either the GNU
7+
* General Public License Version 2 only ("GPL") or the Common Development
8+
* and Distribution License("CDDL") (collectively, the "License"). You
9+
* may not use this file except in compliance with the License. You can
10+
* obtain a copy of the License at
11+
* https://glassfish.dev.java.net/public/CDDL+GPL_1_1.html
12+
* or packager/legal/LICENSE.txt. See the License for the specific
13+
* language governing permissions and limitations under the License.
14+
*
15+
* When distributing the software, include this License Header Notice in each
16+
* file and include the License file at packager/legal/LICENSE.txt.
17+
*
18+
* GPL Classpath Exception:
19+
* Oracle designates this particular file as subject to the "Classpath"
20+
* exception as provided by Oracle in the GPL Version 2 section of the License
21+
* file that accompanied this code.
22+
*
23+
* Modifications:
24+
* If applicable, add the following below the License Header, with the fields
25+
* enclosed by brackets [] replaced by your own identifying information:
26+
* "Portions Copyright [year] [name of copyright owner]"
27+
*
28+
* Contributor(s):
29+
* If you wish your version of this file to be governed by only the CDDL or
30+
* only the GPL Version 2, indicate your decision by adding "[Contributor]
31+
* elects to include this software in this distribution under the [CDDL or GPL
32+
* Version 2] license." If you don't indicate a single choice of license, a
33+
* recipient has the option to distribute your version of this file under
34+
* either the CDDL, the GPL Version 2 or to extend the choice of license to
35+
* its licensees as provided above. However, if you add GPL Version 2 code
36+
* and therefore, elected the GPL Version 2 license, then the option applies
37+
* only if the new code is made subject to such option by the copyright
38+
* holder.
39+
*/
40+
41+
package com.sun.faces.test.servlet30.ajax;
42+
43+
import static org.junit.Assert.assertEquals;
44+
import static org.junit.Assert.assertNotNull;
45+
46+
import org.junit.*;
47+
48+
import com.gargoylesoftware.htmlunit.WebClient;
49+
import com.gargoylesoftware.htmlunit.html.DomElement;
50+
import com.gargoylesoftware.htmlunit.html.HtmlInput;
51+
import com.gargoylesoftware.htmlunit.html.HtmlPage;
52+
53+
public class Issue4340IT {
54+
55+
/**
56+
* Stores the web URL.
57+
*/
58+
private String webUrl;
59+
/**
60+
* Stores the web client.
61+
*/
62+
private WebClient webClient;
63+
64+
@Before
65+
public void setUp() {
66+
webUrl = System.getProperty("integration.url");
67+
webClient = new WebClient();
68+
}
69+
70+
@After
71+
public void tearDown() {
72+
webClient.close();
73+
}
74+
75+
// ------------------------------------------------------------ Test Methods
76+
77+
@Test
78+
public void testAjaxJSResourceAddedToBody() throws Exception {
79+
HtmlPage page = webClient.getPage(webUrl + "faces/issue4340start.xhtml");
80+
81+
HtmlInput issue4340Button = (HtmlInput) page.getElementById("form:issue4340Button");
82+
issue4340Button.click();
83+
84+
webClient.waitForBackgroundJavaScript(60000);
85+
86+
DomElement result = page.getElementById("issue4340Result");
87+
assertNotNull(result);
88+
assertEquals("SUCCESS", result.asText());
89+
}
90+
}

0 commit comments

Comments
 (0)