]> source.dussan.org Git - archiva.git/commitdiff
[MRM-1173] Cannot delete patterns with single and double quotes : fix black list too
authorOlivier Lamy <olamy@apache.org>
Tue, 4 Oct 2011 13:59:23 +0000 (13:59 +0000)
committerOlivier Lamy <olamy@apache.org>
Tue, 4 Oct 2011 13:59:23 +0000 (13:59 +0000)
simplify too  fix for MRM-1135

git-svn-id: https://svn.apache.org/repos/asf/archiva/trunk@1178795 13f79535-47bb-0310-9956-ffa450edef68

archiva-modules/archiva-web/archiva-webapp/src/main/java/org/apache/archiva/web/action/admin/connectors/proxy/AbstractProxyConnectorFormAction.java
archiva-modules/archiva-web/archiva-webapp/src/main/java/org/apache/archiva/web/action/admin/connectors/proxy/EditProxyConnectorAction.java
archiva-modules/archiva-web/archiva-webapp/src/main/webapp/WEB-INF/jsp/admin/include/proxyConnectorForm.jspf

index 19d454eb026580cbd80c3917f94f805d90bc39bf..fc8dd0c80af081532a8926d3b00f71133e6e3cb7 100644 (file)
@@ -28,6 +28,7 @@ import org.apache.archiva.policies.DownloadErrorPolicy;
 import org.apache.archiva.policies.Policy;
 import org.apache.archiva.policies.PostDownloadPolicy;
 import org.apache.archiva.policies.PreDownloadPolicy;
+import org.apache.commons.lang.StringEscapeUtils;
 import org.apache.commons.lang.StringUtils;
 
 import javax.annotation.PostConstruct;
@@ -110,45 +111,12 @@ public abstract class AbstractProxyConnectorFormAction
         this.downloadErrorPolicyMap = getBeansOfType( DownloadErrorPolicy.class );
     }
 
-    protected List<String> escapePatterns( List<String> patterns )
-    {
-        List<String> escapedPatterns = new ArrayList<String>( );
-        if ( patterns != null )
-        {
-            for ( String pattern : patterns )
-            {
-                String escapedPattern =  StringUtils.replace( pattern, "\\", "\\\\" );
-                escapedPatterns.add( escapedPattern );
-            }
-        }
-
-        return escapedPatterns;
-    }
-
-    protected List<String> unescapePatterns( List<String> patterns )
-    {
-        List<String> rawPatterns = new ArrayList<String>( );
-        if ( patterns != null )
-        {
-            for ( String pattern : patterns )
-            {
-                String unescapedPattern = StringUtils.replace( pattern, "\\\\", "\\" );
-                rawPatterns.add( unescapedPattern  );
-            }
-        }
-
-        return rawPatterns;
-    }
-
-    private String escapePattern( String pattern )
-    {
-        return StringUtils.replace( pattern, "\\", "\\\\" );
-    }
-
     public String addBlackListPattern( )
     {
         String pattern = getBlackListPattern( );
 
+        //pattern = StringEscapeUtils.unescapeJavaScript( pattern );
+
         if ( StringUtils.isBlank( pattern ) )
         {
             addActionError( "Cannot add a blank black list pattern." );
@@ -156,7 +124,7 @@ public abstract class AbstractProxyConnectorFormAction
 
         if ( !hasActionErrors( ) )
         {
-            getConnector( ).getBlackListPatterns( ).add( escapePattern( pattern ) );
+            getConnector( ).getBlackListPatterns( ).add( pattern );
             setBlackListPattern( null );
         }
 
@@ -192,7 +160,7 @@ public abstract class AbstractProxyConnectorFormAction
     public String addWhiteListPattern( )
     {
         String pattern = getWhiteListPattern( );
-
+        //pattern = StringEscapeUtils.unescapeJavaScript( pattern );
         if ( StringUtils.isBlank( pattern ) )
         {
             addActionError( "Cannot add a blank white list pattern." );
@@ -200,7 +168,7 @@ public abstract class AbstractProxyConnectorFormAction
 
         if ( !hasActionErrors( ) )
         {
-            getConnector( ).getWhiteListPatterns( ).add( escapePattern( pattern ) );
+            getConnector( ).getWhiteListPatterns( ).add( pattern );
             setWhiteListPattern( null );
         }
 
@@ -276,14 +244,14 @@ public abstract class AbstractProxyConnectorFormAction
         }
 
         if ( !getConnector( ).getBlackListPatterns( ).contains( pattern )
-            && !getConnector( ).getBlackListPatterns( ).contains( StringUtils.replace( pattern, "\\", "\\\\" ) ) )
+            && !getConnector( ).getBlackListPatterns( ).contains( pattern ))
         {
             addActionError( "Non-existant black list pattern [" + pattern + "], no black list pattern removed." );
         }
 
         if ( !hasActionErrors( ) )
         {
-            getConnector( ).getBlackListPatterns( ).remove( escapePattern( pattern ) );
+            getConnector( ).getBlackListPatterns( ).remove( pattern );
         }
 
         setBlackListPattern( null );
@@ -327,14 +295,14 @@ public abstract class AbstractProxyConnectorFormAction
         }
 
         if ( !getConnector( ).getWhiteListPatterns( ).contains( pattern )
-            && !getConnector( ).getWhiteListPatterns( ).contains( StringUtils.replace( pattern, "\\", "\\\\" ) ) )
+            && !getConnector( ).getWhiteListPatterns( ).contains( pattern ))
         {
             addActionError( "Non-existant white list pattern [" + pattern + "], no white list pattern removed." );
         }
 
         if ( !hasActionErrors( ) )
         {
-            getConnector( ).getWhiteListPatterns( ).remove( escapePattern( pattern ) );
+            getConnector( ).getWhiteListPatterns( ).remove( pattern );
         }
 
         setWhiteListPattern( null );
index e3d6003344494af83211de97eda4f187ec31ae01..1a9823e1ec29606ab931e671bdc39d2a59681935 100644 (file)
@@ -62,14 +62,6 @@ public class EditProxyConnectorAction
                     + "]" );
             return ERROR;
         }
-
-        if ( connector != null )
-        {
-            // MRM-1135
-            connector.setBlackListPatterns( escapePatterns( connector.getBlackListPatterns() ) );
-            connector.setWhiteListPatterns( escapePatterns( connector.getWhiteListPatterns() ) );
-        }
-
         return INPUT;
     }
 
index dc06b416fe68650e2bfc0231a89645635878c513..9798158052be0793fdb914670a2a343a9d1fe479 100644 (file)
       </c:when>
       <c:otherwise>
         <table>
-          <c:forEach items="${connector.blackListPatterns}" var="pattern" varStatus="i">
+          <s:iterator value="connector.blackListPatterns" var="currentPattern" status="i">
             <tr>
               <td>
-                <s:hidden name="connector.blackListPatterns" value="%{#attr.pattern}"/>
-                <code>"${pattern}"</code>
+                <input type="hidden" name="connector.blackListPatterns" value="<s:property value="currentPattern" escapeHtml="true"/>"/>
+                <code>"${currentPattern}"</code>
               </td>
               <td>
-                <a href="#" title="Remove [${pattern}] Pattern"
-                      onclick="setAndSubmit('pattern', '${pattern}', 'removeBlackListPattern')">
+                <a href="#" title="Remove [${currentPattern}] Pattern"
+                      onclick="setAndSubmit('pattern', '<s:property value="currentPattern" escapeJavaScript="true"/>', 'removeBlackListPattern')">
                   <img src="${iconDeleteUrl}"/></a>
               </td>
             </tr>
-          </c:forEach>
+          </s:iterator>
         </table>
       </c:otherwise>
     </c:choose>
           <s:iterator value="connector.whiteListPatterns" var="currentPattern" status="i">
             <tr>
               <td>
-                <input type="hidden" name="connector.whiteListPatterns" value="${currentPattern}"/>
+                <input type="hidden" name="connector.whiteListPatterns" value="<s:property value="currentPattern" escapeHtml="true"/>"/>
                 <code>"${currentPattern}"</code>
               </td>
               <td>