[MRM-1173] Cannot delete patterns with single and double quotes : fix black list too

simplify too  fix for MRM-1135

git-svn-id: https://svn.apache.org/repos/asf/archiva/trunk@1178795 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Olivier Lamy 2011-10-04 13:59:23 +00:00
parent ebcabb17a3
commit 2de2460457
3 changed files with 17 additions and 57 deletions

View 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 );

View 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;
}

View File

@ -134,19 +134,19 @@
</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>
@ -176,7 +176,7 @@
<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>