cocoon-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jo...@apache.org
Subject svn commit: r746648 - in /cocoon/trunk/core: cocoon-core/src/test/java/org/apache/cocoon/selection/ cocoon-core/src/test/resources/org/apache/cocoon/selection/ cocoon-sitemap/cocoon-sitemap-components/src/changes/ cocoon-sitemap/cocoon-sitemap-componen...
Date Sun, 22 Feb 2009 08:49:26 GMT
Author: joerg
Date: Sun Feb 22 08:49:25 2009
New Revision: 746648

URL: http://svn.apache.org/viewvc?rev=746648&view=rev
Log:
COCOON-1887: Change HostSelector to be case-insensitive according to RFC3986 section 3.2.2.

Modified:
    cocoon/trunk/core/cocoon-core/src/test/java/org/apache/cocoon/selection/HostSelectorTestCase.java
    cocoon/trunk/core/cocoon-core/src/test/resources/org/apache/cocoon/selection/HostSelectorTestCase.xtest
    cocoon/trunk/core/cocoon-sitemap/cocoon-sitemap-components/src/changes/changes.xml
    cocoon/trunk/core/cocoon-sitemap/cocoon-sitemap-components/src/main/java/org/apache/cocoon/selection/HostSelector.java
    cocoon/trunk/core/cocoon-sitemap/cocoon-sitemap-impl/src/main/java/org/apache/cocoon/selection/NamedPatternsSelector.java

Modified: cocoon/trunk/core/cocoon-core/src/test/java/org/apache/cocoon/selection/HostSelectorTestCase.java
URL: http://svn.apache.org/viewvc/cocoon/trunk/core/cocoon-core/src/test/java/org/apache/cocoon/selection/HostSelectorTestCase.java?rev=746648&r1=746647&r2=746648&view=diff
==============================================================================
--- cocoon/trunk/core/cocoon-core/src/test/java/org/apache/cocoon/selection/HostSelectorTestCase.java
(original)
+++ cocoon/trunk/core/cocoon-core/src/test/java/org/apache/cocoon/selection/HostSelectorTestCase.java
Sun Feb 22 08:49:25 2009
@@ -19,13 +19,14 @@
 import junit.framework.Test;
 import junit.framework.TestSuite;
 import junit.textui.TestRunner;
+
 import org.apache.avalon.framework.parameters.Parameters;
 import org.apache.cocoon.SitemapComponentTestCase;
 
 
 public class HostSelectorTestCase extends SitemapComponentTestCase {
 
-    private final String HOST_SELECTOR = "host";
+    private static final String HOST_SELECTOR = "host";
 
     /**
      * Run this test suite from commandline
@@ -92,4 +93,30 @@
         System.out.println(result);
         assertTrue( "Test if host is not " + expectedHostName, !result );
     }
+
+    /**
+     * Test the host selector matches regardless of whether the hostname and
+     * value are upper or lower case.
+     */
+    public void testHostCaseInsensitive() throws Exception {
+        final String hostLower = "myhost-dns-name";
+        final String hostUpper = "MYHOST-DNS-NAME-IN-A-EUROPE-COUNTRY";
+        String expectedHostName;
+
+        Parameters parameters = new Parameters();
+        boolean result;
+
+        getRequest().setHeader("Host", hostUpper);
+        expectedHostName = "myhost-eu";
+        result = this.select(HOST_SELECTOR, expectedHostName, parameters);
+        System.out.println(result);
+        assertTrue("Test upper case host doesn't match lower case value as expected.", result);
+
+        getRequest().setHeader("Host", hostLower);
+        expectedHostName = "myhost-uppercase";
+        result = this.select(HOST_SELECTOR, expectedHostName, parameters);
+        System.out.println(result);
+        assertTrue("Test lower case host doesn't match upper case value as expected.", result);
+    }
+
 }

Modified: cocoon/trunk/core/cocoon-core/src/test/resources/org/apache/cocoon/selection/HostSelectorTestCase.xtest
URL: http://svn.apache.org/viewvc/cocoon/trunk/core/cocoon-core/src/test/resources/org/apache/cocoon/selection/HostSelectorTestCase.xtest?rev=746648&r1=746647&r2=746648&view=diff
==============================================================================
--- cocoon/trunk/core/cocoon-core/src/test/resources/org/apache/cocoon/selection/HostSelectorTestCase.xtest
(original)
+++ cocoon/trunk/core/cocoon-core/src/test/resources/org/apache/cocoon/selection/HostSelectorTestCase.xtest
Sun Feb 22 08:49:25 2009
@@ -28,6 +28,7 @@
                        name="host">
       <host name="myhost-eu" value="myhost-dns-name-in-a-europe-country"/>
       <host name="myhost-us" value="myhost-dns-name-in-a-us-state"/>
+      <host name="myhost-uppercase" value="MYHOST-DNS-NAME"/>
     </component-instance>
   </selectors>
  </components>

Modified: cocoon/trunk/core/cocoon-sitemap/cocoon-sitemap-components/src/changes/changes.xml
URL: http://svn.apache.org/viewvc/cocoon/trunk/core/cocoon-sitemap/cocoon-sitemap-components/src/changes/changes.xml?rev=746648&r1=746647&r2=746648&view=diff
==============================================================================
--- cocoon/trunk/core/cocoon-sitemap/cocoon-sitemap-components/src/changes/changes.xml (original)
+++ cocoon/trunk/core/cocoon-sitemap/cocoon-sitemap-components/src/changes/changes.xml Sun
Feb 22 08:49:25 2009
@@ -24,6 +24,11 @@
     +-->
 <document>
   <body>
+    <release version="1.0.1" date="TBD" description="to be done">
+      <action dev="joerg" type="update" fixes-bug="COCOON-1887" due-to="Andrew Stevens"
due-to-email="stevensa@users.sourceforge.net">
+        Change HostSelector to be case-insensitive according to RFC3986 section 3.2.2.
+      </action>
+    </release>
     <release version="1.0.0" date="TBA" description="released">
       <action dev="rgoers" type="fix" issue="COCOON-1574">
         Created XPathXMLFileModule to fix problems with XMLFileModule. Added getAttributeValue
to JXPathHelper

Modified: cocoon/trunk/core/cocoon-sitemap/cocoon-sitemap-components/src/main/java/org/apache/cocoon/selection/HostSelector.java
URL: http://svn.apache.org/viewvc/cocoon/trunk/core/cocoon-sitemap/cocoon-sitemap-components/src/main/java/org/apache/cocoon/selection/HostSelector.java?rev=746648&r1=746647&r2=746648&view=diff
==============================================================================
--- cocoon/trunk/core/cocoon-sitemap/cocoon-sitemap-components/src/main/java/org/apache/cocoon/selection/HostSelector.java
(original)
+++ cocoon/trunk/core/cocoon-sitemap/cocoon-sitemap-components/src/main/java/org/apache/cocoon/selection/HostSelector.java
Sun Feb 22 08:49:25 2009
@@ -16,12 +16,13 @@
  */
 package org.apache.cocoon.selection;
 
+import java.util.Map;
+
 import org.apache.avalon.framework.configuration.Configuration;
 import org.apache.avalon.framework.configuration.ConfigurationException;
 import org.apache.avalon.framework.parameters.Parameters;
-import org.apache.cocoon.environment.ObjectModelHelper;
 
-import java.util.Map;
+import org.apache.cocoon.environment.ObjectModelHelper;
 
 /**
  * A <code>Selector</code> that matches a string from within the host parameter
@@ -68,6 +69,6 @@
             return false;
         }
 
-        return checkPatterns(expression, host);
+        return checkPatterns(expression, host, false);
     }
 }

Modified: cocoon/trunk/core/cocoon-sitemap/cocoon-sitemap-impl/src/main/java/org/apache/cocoon/selection/NamedPatternsSelector.java
URL: http://svn.apache.org/viewvc/cocoon/trunk/core/cocoon-sitemap/cocoon-sitemap-impl/src/main/java/org/apache/cocoon/selection/NamedPatternsSelector.java?rev=746648&r1=746647&r2=746648&view=diff
==============================================================================
--- cocoon/trunk/core/cocoon-sitemap/cocoon-sitemap-impl/src/main/java/org/apache/cocoon/selection/NamedPatternsSelector.java
(original)
+++ cocoon/trunk/core/cocoon-sitemap/cocoon-sitemap-impl/src/main/java/org/apache/cocoon/selection/NamedPatternsSelector.java
Sun Feb 22 08:49:25 2009
@@ -95,7 +95,7 @@
     }
 
     /**
-     * Checks if <code>value</code> is a substring of one of the patterns associated
+     * Checks if <code>value</code> is a (case-sensitive) substring of one of
the patterns associated
      * to <code>expression</code>
      *
      * @param expression the expression that is selected
@@ -103,6 +103,19 @@
      * @return true if <code>value</code> matches one of the patterns
      */
     protected boolean checkPatterns(String expression, String value) {
+        return checkPatterns(expression, value, true);
+    }
+
+    /**
+     * Checks if <code>value</code> is a substring of one of the patterns associated
+     * to <code>expression</code>
+     *
+     * @param expression the expression that is selected
+     * @param value the value to check
+     * @param caseSensitive boolean switch whether comparison is done case-sensitive  
+     * @return true if <code>value</code> matches one of the patterns
+     */
+    protected boolean checkPatterns(String expression, String value, boolean caseSensitive)
{
         if (value == null) {
             getLogger().debug("No value given -- failing.");
             return false;
@@ -114,9 +127,14 @@
             return false;
         }
 
+        if (!caseSensitive) {
+            value = value.toLowerCase();
+        }
+
         // Does a pattern match 'value' ?
         for (int i = 0; i < patterns.length; i++) {
-            if (value.indexOf(patterns[i]) != -1) {
+            if ((caseSensitive && value.indexOf(patterns[i]) != -1)
+                || (!caseSensitive && value.indexOf(patterns[i].toLowerCase()) !=
-1)) {
                 getLogger().debug(expression + " selected value " + value);
                 return true;
             }



Mime
View raw message