git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@697139 13f79535-47bb-0310-9956-ffa450edef68master
@@ -222,6 +222,10 @@ Fixed bugs: | |||||
regardless of their configuration. | regardless of their configuration. | ||||
Bugzilla Report 37970. | Bugzilla Report 37970. | ||||
* <signjar> and <issigned> didn't handle aliases with characters other | |||||
than numbers, letters, hyphen or underscore properly. | |||||
Bugzilla Report 45820. | |||||
Other changes: | Other changes: | ||||
-------------- | -------------- | ||||
@@ -80,6 +80,11 @@ | |||||
<assertSigned/> | <assertSigned/> | ||||
</target> | </target> | ||||
<target name="invalidchars" depends="jar"> | |||||
<sign alias="test@nly"/> | |||||
<assertSigned/> | |||||
</target> | |||||
<target name="maxmemory" depends="jar"> | <target name="maxmemory" depends="jar"> | ||||
<sign maxmemory="128m"/> | <sign maxmemory="128m"/> | ||||
<assertSigned/> | <assertSigned/> | ||||
@@ -23,6 +23,7 @@ import java.util.Enumeration; | |||||
import org.apache.tools.ant.BuildException; | import org.apache.tools.ant.BuildException; | ||||
import org.apache.tools.ant.Project; | import org.apache.tools.ant.Project; | ||||
import org.apache.tools.ant.taskdefs.ManifestTask; | |||||
import org.apache.tools.ant.types.DataType; | import org.apache.tools.ant.types.DataType; | ||||
import org.apache.tools.zip.ZipEntry; | import org.apache.tools.zip.ZipEntry; | ||||
import org.apache.tools.zip.ZipFile; | import org.apache.tools.zip.ZipFile; | ||||
@@ -84,6 +85,7 @@ public class IsSigned extends DataType implements Condition { | |||||
} | } | ||||
return false; | return false; | ||||
} | } | ||||
name = replaceInvalidChars(name); | |||||
boolean shortSig = jarFile.getEntry(SIG_START | boolean shortSig = jarFile.getEntry(SIG_START | ||||
+ name.toUpperCase() | + name.toUpperCase() | ||||
+ SIG_END) != null; | + SIG_END) != null; | ||||
@@ -131,4 +133,20 @@ public class IsSigned extends DataType implements Condition { | |||||
} | } | ||||
return r; | return r; | ||||
} | } | ||||
private static String replaceInvalidChars(final String name) { | |||||
StringBuffer sb = new StringBuffer(); | |||||
final int len = name.length(); | |||||
boolean changes = false; | |||||
for (int i = 0; i < len; i++) { | |||||
final char ch = name.charAt(i); | |||||
if (ManifestTask.VALID_ATTRIBUTE_CHARS.indexOf(ch) < 0) { | |||||
sb.append("_"); | |||||
changes = true; | |||||
} else { | |||||
sb.append(ch); | |||||
} | |||||
} | |||||
return changes ? sb.toString() : name; | |||||
} | |||||
} | } |
@@ -70,6 +70,17 @@ public class SignJarTest extends BuildFileTest { | |||||
sj.isSigned()); | sj.isSigned()); | ||||
} | } | ||||
public void testInvalidChars() { | |||||
executeTarget("invalidchars"); | |||||
SignJarChild sj = new SignJarChild(); | |||||
sj.setAlias("test@nly"); | |||||
sj.setKeystore("testkeystore"); | |||||
sj.setStorepass("apacheant"); | |||||
File jar = new File(getProject().getProperty("test.jar")); | |||||
sj.setJar(jar); | |||||
assertTrue(sj.isSigned()); | |||||
} | |||||
/** | /** | ||||
* subclass in order to get access to protected isSigned method if | * subclass in order to get access to protected isSigned method if | ||||
* tests and task come from different classloaders. | * tests and task come from different classloaders. | ||||