Skip to content

Commit 46bda32

Browse files
committed
Possible fix for encoding problems in redirect rules
1 parent 3d74dce commit 46bda32

2 files changed

Lines changed: 18 additions & 16 deletions

File tree

‎core/src/main/java/com/ocpsoft/pretty/PrettyFilter.java‎

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -190,10 +190,12 @@ else if (queryString == null)
190190
else if ((ruleUrl != null) && !"".equals(ruleUrl.trim()))
191191
{
192192
/*
193-
* This is a custom location - don't URLEncode, just
194-
* redirect
193+
* This is a custom location - don't call encodeRedirectURL(),
194+
* just redirect to the encoded URL
195195
*/
196-
resp.setHeader("Location", newUrl);
196+
URL encodedNewUrl = new URL(newUrl).encode();
197+
String location = req.getContextPath() + encodedNewUrl.toURL();
198+
resp.setHeader("Location", location);
197199
resp.setStatus(rule.getRedirect().getStatus());
198200
resp.setCharacterEncoding(url.getEncoding());
199201
resp.flushBuffer();

‎tests-jsf2/src/test/java/com/ocpsoft/pretty/faces/test/encoding/URLEncodingTest.java‎

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -59,19 +59,19 @@ public void testRewriteEncoding() throws Exception
5959
{
6060
String target = "/virtual";
6161
String expected = "/virtuální";
62-
//
63-
// JSFSession jsfSession = new JSFSession(target);
64-
// JSFServerSession server = jsfSession.getJSFServerSession();
65-
//
66-
// JSFClientSession client = jsfSession.getJSFClientSession();
67-
// String action = client.getElement("form").getAttribute("action");
68-
//
69-
// FacesContext context = server.getFacesContext();
70-
// PrettyContext prettyContext =
71-
// PrettyContext.getCurrentInstance(context);
72-
//
73-
// assertEquals(expected, prettyContext.getRequestURL().toString());
74-
// assertEquals(prettyContext.getContextPath() + expected, action);
62+
63+
JSFSession jsfSession = new JSFSession(target);
64+
JSFServerSession server = jsfSession.getJSFServerSession();
65+
66+
JSFClientSession client = jsfSession.getJSFClientSession();
67+
String action = client.getElement("form").getAttribute("action");
68+
69+
FacesContext context = server.getFacesContext();
70+
PrettyContext prettyContext =
71+
PrettyContext.getCurrentInstance(context);
72+
73+
assertEquals(expected, prettyContext.getRequestURL().toString());
74+
assertEquals(prettyContext.getContextPath() + expected, action);
7575
}
7676

7777
@Test

0 commit comments

Comments
 (0)