tapestry-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From hls...@apache.org
Subject svn commit: r1001102 - in /tapestry/tapestry5/trunk/tapestry-core/src: main/java/org/apache/tapestry5/internal/services/ main/resources/org/apache/tapestry5/ test/app1/nested/ test/java/org/apache/tapestry5/integration/app1/pages/nested/
Date Fri, 24 Sep 2010 23:00:33 GMT
Author: hlship
Date: Fri Sep 24 23:00:33 2010
New Revision: 1001102

URL: http://svn.apache.org/viewvc?rev=1001102&view=rev
Log:
TAP5-1004: URLEncode the exception message encoded as a response header and decode it on the
client before displaying it to the user

Modified:
    tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/DefaultRequestExceptionHandler.java
    tapestry/tapestry5/trunk/tapestry-core/src/main/resources/org/apache/tapestry5/tapestry.js
    tapestry/tapestry5/trunk/tapestry-core/src/test/app1/nested/ZoneDemo.tml
    tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/pages/nested/ZoneDemo.java

Modified: tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/DefaultRequestExceptionHandler.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/DefaultRequestExceptionHandler.java?rev=1001102&r1=1001101&r2=1001102&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/DefaultRequestExceptionHandler.java
(original)
+++ tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/DefaultRequestExceptionHandler.java
Fri Sep 24 23:00:33 2010
@@ -4,7 +4,7 @@
 // you may not use this file except in compliance with the License.
 // You may obtain a copy of the License at
 //
-//     http://www.apache.org/licenses/LICENSE-2.0
+// http://www.apache.org/licenses/LICENSE-2.0
 //
 // Unless required by applicable law or agreed to in writing, software
 // distributed under the License is distributed on an "AS IS" BASIS,
@@ -15,6 +15,7 @@
 package org.apache.tapestry5.internal.services;
 
 import java.io.IOException;
+import java.net.URLEncoder;
 
 import javax.servlet.http.HttpServletResponse;
 
@@ -45,10 +46,10 @@ public class DefaultRequestExceptionHand
 
     public DefaultRequestExceptionHandler(RequestPageCache pageCache, PageResponseRenderer
renderer, Logger logger,
 
-                                           @Symbol(SymbolConstants.EXCEPTION_REPORT_PAGE)
-                                          String pageName,
+    @Symbol(SymbolConstants.EXCEPTION_REPORT_PAGE)
+    String pageName,
 
-                                          Response response)
+    Response response)
     {
         this.pageCache = pageCache;
         this.renderer = renderer;
@@ -64,7 +65,14 @@ public class DefaultRequestExceptionHand
         // TAP5-233: Make sure the client knows that an error occurred.
 
         response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
-        response.setHeader("X-Tapestry-ErrorMessage", InternalUtils.toMessage(exception));
+
+        String rawMessage = InternalUtils.toMessage(exception);
+
+        // Encode it compatibly with the JavaScript escape() function.
+
+        String encoded = URLEncoder.encode(rawMessage, "UTF-8").replace("+", "%20");
+
+        response.setHeader("X-Tapestry-ErrorMessage", encoded);
 
         Page page = pageCache.get(pageName);
 

Modified: tapestry/tapestry5/trunk/tapestry-core/src/main/resources/org/apache/tapestry5/tapestry.js
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/main/resources/org/apache/tapestry5/tapestry.js?rev=1001102&r1=1001101&r2=1001102&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/main/resources/org/apache/tapestry5/tapestry.js
(original)
+++ tapestry/tapestry5/trunk/tapestry-core/src/main/resources/org/apache/tapestry5/tapestry.js
Fri Sep 24 23:00:33 2010
@@ -368,8 +368,10 @@ var Tapestry = {
 	 * Default function for handling Ajax-related failures.
 	 */
 	ajaxFailureHandler : function(response) {
-		var message = response.getHeader("X-Tapestry-ErrorMessage");
+		var rawMessage = response.getHeader("X-Tapestry-ErrorMessage");
 
+		var message = unescape(rawMessage).escapeHTML();
+		
 		Tapestry.error(Tapestry.Messages.communicationFailed + message);
 
 		Tapestry.debug(Tapestry.Messages.ajaxFailure + message, response);

Modified: tapestry/tapestry5/trunk/tapestry-core/src/test/app1/nested/ZoneDemo.tml
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/test/app1/nested/ZoneDemo.tml?rev=1001102&r1=1001101&r2=1001102&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/test/app1/nested/ZoneDemo.tml (original)
+++ tapestry/tapestry5/trunk/tapestry-core/src/test/app1/nested/ZoneDemo.tml Fri Sep 24 23:00:33
2010
@@ -71,6 +71,9 @@
     <li>
       <t:actionlink t:id="blankUpdate" zone="output">Blank the zone</t:actionlink>
     </li>
+    <li>
+      <t:actionlink t:id="poorlyFormattedFail" zone="output">Poorly formatted server-side
failure</t:actionlink>
+    </li>
   </ul>
 
   <t:block id="empty"/>

Modified: tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/pages/nested/ZoneDemo.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/pages/nested/ZoneDemo.java?rev=1001102&r1=1001101&r2=1001102&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/pages/nested/ZoneDemo.java
(original)
+++ tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/pages/nested/ZoneDemo.java
Fri Sep 24 23:00:33 2010
@@ -95,6 +95,11 @@ public class ZoneDemo
         throw new RuntimeException("Server-side exception.");
     }
 
+    void onActionFromPoorlyFormattedFail()
+    {
+        throw new RuntimeException("Failure &\n\n<Stuff>!");
+    }
+    
     Object onSuccessFromRegistrationForm()
     {
         return registrationOutput;



Mime
View raw message