Skip to content

Commit 79d994d

Browse files
committed
added test for rewrite rule encoding, currently failing
1 parent ab00fe7 commit 79d994d

4 files changed

Lines changed: 49 additions & 4 deletions

File tree

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -193,9 +193,9 @@ else if ((ruleUrl != null) && !"".equals(ruleUrl.trim()))
193193
* This is a custom location - don't URLEncode, just
194194
* redirect
195195
*/
196-
String redirectURL = resp.encodeRedirectURL(newUrl);
197-
resp.setHeader("Location", redirectURL);
196+
resp.setHeader("Location", newUrl);
198197
resp.setStatus(rule.getRedirect().getStatus());
198+
resp.setCharacterEncoding(url.getEncoding());
199199
resp.flushBuffer();
200200
break;
201201
}

‎core/src/main/java/com/ocpsoft/pretty/faces/annotation/URLAction.java‎

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,18 @@
1+
/*
2+
* Copyright 2010 Lincoln Baxter, III
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, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
116
package com.ocpsoft.pretty.faces.annotation;
217

318
import java.lang.annotation.Documented;

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

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,26 @@ public static Archive<?> createDeployment()
5353
.setWebXML("jsf-web.xml");
5454
}
5555

56+
@Test
57+
// http://code.google.com/p/prettyfaces/issues/detail?id=76
58+
public void testRewriteEncoding() throws Exception
59+
{
60+
String target = "/virtual";
61+
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 = PrettyContext.getCurrentInstance(context);
71+
72+
assertEquals(expected, prettyContext.getRequestURL().toString());
73+
assertEquals(prettyContext.getContextPath() + expected, action);
74+
}
75+
5676
@Test
5777
public void testPrettyFacesFormActionURLEncodesProperly() throws Exception
5878
{
@@ -139,7 +159,7 @@ public void testQueryDecoding() throws Exception
139159
@Test
140160
public void testQueryWithGermanUmlaut() throws Exception
141161
{
142-
162+
143163
// query parameter contains a German 'ü' encoded with UTF8
144164
JSFSession jsfSession = new JSFSession("/encoding/Vračar?dis=%C3%BC");
145165
JSFServerSession server = jsfSession.getJSFServerSession();
@@ -149,7 +169,7 @@ public void testQueryWithGermanUmlaut() throws Exception
149169
Object val2 = server.getManagedBeanValue("#{encodingBean.queryText}");
150170
assertEquals("\u00fc", val2);
151171
}
152-
172+
153173
@Test
154174
public void testPatternDecoding() throws Exception
155175
{

‎tests-jsf2/src/test/resources/encoding/encoding-pretty-config.xml‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,4 +28,14 @@
2828
<view-id> /encoding.jsf </view-id>
2929
</url-mapping>
3030

31+
<rewrite match="^/virtual$" url="/virtuální" redirect="301" />
32+
<!--
33+
<rewrite match="^/virtualencoded$" url="/virtu%C3%A1ln%C3%AD" redirect="301" />
34+
-->
35+
36+
<url-mapping id="virtual">
37+
<pattern value="/virtuální"></pattern>
38+
<view-id>/encoding.jsf</view-id>
39+
</url-mapping>
40+
3141
</pretty-config>

0 commit comments

Comments
 (0)