Skip to content

Commit 0afa163

Browse files
authored
Merge pull request #90 from prime-framework/degroff/fix_handleFollowMetaRefresh4x
degroff/fix handle follow meta refresh
2 parents 0c36555 + 1c2031b commit 0afa163

File tree

9 files changed

+115
-5
lines changed

9 files changed

+115
-5
lines changed

build.savant

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ logbackVersion = "1.4.14"
2929
slf4jVersion = "2.0.13"
3030
testngVersion = "7.8.0"
3131

32-
project(group: "org.primeframework", name: "prime-mvc", version: "4.35.0", licenses: ["ApacheV2_0"]) {
32+
project(group: "org.primeframework", name: "prime-mvc", version: "4.35.1", licenses: ["ApacheV2_0"]) {
3333
workflow {
3434
fetch {
3535
// Dependency resolution order:

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
<groupId>org.primeframework</groupId>
77
<artifactId>prime-mvc</artifactId>
8-
<version>4.35.0</version>
8+
<version>4.35.1</version>
99
<packaging>jar</packaging>
1010

1111
<name>FusionAuth App</name>
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
/*
2+
* Copyright (c) 2025, Inversoft Inc., All Rights Reserved
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing,
11+
* software distributed under the License is distributed on an
12+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
13+
* either express or implied. See the License for the specific
14+
* language governing permissions and limitations under the License.
15+
*/
16+
package org.example.action.meta;
17+
18+
import org.primeframework.mvc.ErrorException;
19+
import org.primeframework.mvc.action.annotation.Action;
20+
import org.primeframework.mvc.action.result.annotation.Forward;
21+
22+
/**
23+
* @author Daniel DeGroff
24+
*/
25+
@Action
26+
@Forward.List({
27+
@Forward(code = "input-lc", page = "/meta/refresh-lc.ftl"),
28+
@Forward(code = "input-uc", page = "/meta/refresh-uc.ftl")
29+
})
30+
public class RefreshAction {
31+
public String test = "lc";
32+
33+
public String get() {
34+
if (test == null || !(test.equals("lc") || test.equals("uc"))) {
35+
throw new ErrorException("error");
36+
}
37+
38+
return "input-" + test;
39+
}
40+
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
/*
2+
* Copyright (c) 2025, Inversoft Inc., All Rights Reserved
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing,
11+
* software distributed under the License is distributed on an
12+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
13+
* either express or implied. See the License for the specific
14+
* language governing permissions and limitations under the License.
15+
*/
16+
package org.example.action.meta;
17+
18+
import org.primeframework.mvc.action.annotation.Action;
19+
20+
/**
21+
* @author Daniel DeGroff
22+
*/
23+
@Action
24+
public class TargetAction {
25+
public String get() {
26+
return "input";
27+
}
28+
}

src/test/java/org/primeframework/mvc/GlobalTest.java

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,30 @@ public void flash_scope_compatibility() throws Exception {
213213
;
214214
}
215215

216+
@Test
217+
public void follow_meta_refresh() throws Exception {
218+
// use upper case Refresh and URL, and lower case refresh and url
219+
test.forEach("lc", "uc")
220+
.test(param -> test
221+
.simulate(() -> simulator
222+
.test("/meta/refresh")
223+
.withURLParameter("test", param)
224+
.get()
225+
.assertStatusCode(200)
226+
.assertBodyContains("""
227+
<meta http-equiv="{refresh}" content="0; {url}=/meta/target">
228+
"""
229+
.replace("{refresh}", param.equals("uc") ? "Refresh" : "refresh")
230+
.replace("{url}", param.equals("uc") ? "URL" : "url"))
231+
232+
.followMetaRefresh(result -> result
233+
.assertStatusCode(200)
234+
.assertBody("""
235+
We made it!
236+
""")))
237+
);
238+
}
239+
216240
@Test
217241
public void get() throws Exception {
218242
// Not called yet

src/test/java/org/primeframework/mvc/test/RequestResult.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1893,13 +1893,14 @@ private RequestResult handleFollowMetaRefresh(ThrowingConsumer<RequestResult> re
18931893
if (element.hasAttr("http-equiv")) {
18941894
String value = element.attr("http-equiv");
18951895
// Never null
1896-
if (value.equals("refresh")) {
1896+
if (value.equalsIgnoreCase("refresh")) {
18971897
String content = element.attr("content");
18981898
// Handle this
18991899
String[] parts = content.split(";");
19001900
for (String part : parts) {
1901-
if (part.startsWith("URL=")) {
1902-
String uri = part.substring(4);
1901+
String trimmedPart = part.trim();
1902+
if (trimmedPart.toLowerCase(Locale.ROOT).startsWith("url=")) {
1903+
String uri = trimmedPart.substring(4);
19031904
if (uri.startsWith("'")) {
19041905
uri = uri.substring(1, uri.length() - 1);
19051906
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<html lang="en_US">
2+
[#-- Note that refresh and URL are intentionally lowercase--]
3+
<head>
4+
<meta http-equiv="refresh" content="0; url=/meta/target">
5+
<title>Refresh please</title>
6+
</head>
7+
<body></body>
8+
</html>
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<html lang="en_US">
2+
[#-- Note that refresh and URL are intentionally lowercase--]
3+
<head>
4+
<meta http-equiv="Refresh" content="0; URL=/meta/target">
5+
<title>Refresh please</title>
6+
</head>
7+
<body></body>
8+
</html>
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
We made it!

0 commit comments

Comments
 (0)