Author: mrdon
Date: Tue Jul 18 22:42:21 2006
New Revision: 423378

URL: http://svn.apache.org/viewvc?rev=423378&view=rev
Log:
Changed action mapper to always add the extension when building a uri to
prevent the masking of cases where the user adds the extension when it
shouldn't be there like the form's action attribute
WW-1323

Modified:
    
struts/struts2/trunk/core/src/main/java/org/apache/struts2/dispatcher/mapper/DefaultActionMapper.java
    
struts/struts2/trunk/core/src/test/java/org/apache/struts2/dispatcher/mapper/DefaultActionMapperTest.java

Modified: 
struts/struts2/trunk/core/src/main/java/org/apache/struts2/dispatcher/mapper/DefaultActionMapper.java
URL: 
http://svn.apache.org/viewvc/struts/struts2/trunk/core/src/main/java/org/apache/struts2/dispatcher/mapper/DefaultActionMapper.java?rev=423378&r1=423377&r2=423378&view=diff
==============================================================================
--- 
struts/struts2/trunk/core/src/main/java/org/apache/struts2/dispatcher/mapper/DefaultActionMapper.java
 (original)
+++ 
struts/struts2/trunk/core/src/main/java/org/apache/struts2/dispatcher/mapper/DefaultActionMapper.java
 Tue Jul 18 22:42:21 2006
@@ -379,10 +379,15 @@
         }
 
         String extension = getDefaultExtension();
-        if ( extension != null && uri.indexOf( '.' + extension) == -1  ) {
-            uri.append(".").append(extension);
-            if ( params.length() > 0) {
-                uri.append(params);
+        if ( extension != null) {
+            
+            // When in compatibility mode, we don't add an extension if it 
exists already
+            // otherwise, we always add it
+            if (!compatibilityMode || (compatibilityMode && uri.indexOf( '.' + 
extension) == -1  )) {
+                uri.append(".").append(extension);
+                if ( params.length() > 0) {
+                    uri.append(params);
+                }
             }
         }
 

Modified: 
struts/struts2/trunk/core/src/test/java/org/apache/struts2/dispatcher/mapper/DefaultActionMapperTest.java
URL: 
http://svn.apache.org/viewvc/struts/struts2/trunk/core/src/test/java/org/apache/struts2/dispatcher/mapper/DefaultActionMapperTest.java?rev=423378&r1=423377&r2=423378&view=diff
==============================================================================
--- 
struts/struts2/trunk/core/src/test/java/org/apache/struts2/dispatcher/mapper/DefaultActionMapperTest.java
 (original)
+++ 
struts/struts2/trunk/core/src/test/java/org/apache/struts2/dispatcher/mapper/DefaultActionMapperTest.java
 Tue Jul 18 22:42:21 2006
@@ -247,6 +247,16 @@
 
         // TODO: need to test location but there's noaccess to the 
property/method, unless we use reflection
     }
+    
+    public void testDropExtension() throws Exception {
+        DefaultActionMapper mapper = new DefaultActionMapper();
+        String name = mapper.dropExtension("foo.action");
+        assertTrue("Name not right: "+name, "foo".equals(name));
+        
+        name = mapper.dropExtension("foo.action.action");
+        assertTrue("Name not right: "+name, "foo.action".equals(name));
+        
+    }
 
     public void testGetUriFromActionMapper1() throws Exception {
         DefaultActionMapper mapper = new DefaultActionMapper();
@@ -355,6 +365,33 @@
         String uri = mapper.getUriFromActionMapping(actionMapping);
 
         assertEquals("/myActionName.action?test=bla", uri);
+    }
+    
+    public void testGetUriFromActionMapper11() throws Exception {
+        DefaultActionMapper mapper = new DefaultActionMapper();
+        ActionMapping actionMapping = new ActionMapping();
+        actionMapping.setName("myActionName.action");
+        actionMapping.setNamespace("/");
+        String uri = mapper.getUriFromActionMapping(actionMapping);
+
+        assertEquals("/myActionName.action.action", uri);
+    }
+    
+    public void testGetUriFromActionMapper12() throws Exception {
+        Object old = 
org.apache.struts2.config.Configuration.get(StrutsConstants.STRUTS_COMPATIBILITY_MODE);
+        
org.apache.struts2.config.Configuration.set(StrutsConstants.STRUTS_COMPATIBILITY_MODE,
 "true");
+        try {
+            DefaultActionMapper mapper = new DefaultActionMapper();
+            ActionMapping actionMapping = new ActionMapping();
+            actionMapping.setName("myActionName.action");
+            actionMapping.setNamespace("/");
+            String uri = mapper.getUriFromActionMapping(actionMapping);
+
+            assertEquals("/myActionName.action", uri);
+        }
+        finally {
+            
org.apache.struts2.config.Configuration.set(StrutsConstants.STRUTS_COMPATIBILITY_MODE,
 old);
+        }
     }
 
 }


Reply via email to