From c7f7d99c3d53fbd9c018a8513532faec64a61f2e Mon Sep 17 00:00:00 2001 From: Jan Materne Date: Fri, 20 Apr 2007 06:25:05 +0000 Subject: [PATCH] Add tests. Document the regexp for attribute name. git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@530664 13f79535-47bb-0310-9956-ffa450edef68 --- docs/manual/CoreTasks/manifest.html | 4 +++- src/etc/testcases/taskdefs/manifest.xml | 18 ++++++++++++++ .../tools/ant/taskdefs/ManifestTask.java | 8 +++---- .../tools/ant/taskdefs/ManifestTest.java | 24 +++++++++++++------ 4 files changed, 42 insertions(+), 12 deletions(-) diff --git a/docs/manual/CoreTasks/manifest.html b/docs/manual/CoreTasks/manifest.html index 82b7a2f2d..60cf1808b 100644 --- a/docs/manual/CoreTasks/manifest.html +++ b/docs/manual/CoreTasks/manifest.html @@ -94,7 +94,9 @@ not nested into a section will be added to the "Main" section.

name - the name of the attribute. + the name of the attribute,
+ must match the regexp [A-Za-z0-9][A-Za-z0-9-_]*. + Yes diff --git a/src/etc/testcases/taskdefs/manifest.xml b/src/etc/testcases/taskdefs/manifest.xml index ac06e2346..1018c8d3f 100644 --- a/src/etc/testcases/taskdefs/manifest.xml +++ b/src/etc/testcases/taskdefs/manifest.xml @@ -227,6 +227,24 @@ + + + + + + + + + + + + + + + + + + diff --git a/src/main/org/apache/tools/ant/taskdefs/ManifestTask.java b/src/main/org/apache/tools/ant/taskdefs/ManifestTask.java index 6636ef605..18793c61a 100644 --- a/src/main/org/apache/tools/ant/taskdefs/ManifestTask.java +++ b/src/main/org/apache/tools/ant/taskdefs/ManifestTask.java @@ -139,20 +139,20 @@ public class ManifestTask extends Task { * check each character. * * @param attribute The attribute to check - * @throws ManifestException if the check fails + * @throws BuildException if the check fails */ - private void checkAttribute(Manifest.Attribute attribute) throws ManifestException { + private void checkAttribute(Manifest.Attribute attribute) throws BuildException { String name = attribute.getName(); char ch = name.charAt(0); if (ch == '-' || ch == '_') { - throw new ManifestException("Manifest attribute names must not contain '" + ch + "'"); + throw new BuildException("Manifest attribute names must not contain '" + ch + "' at the begin."); } for (int i = 0; i < name.length(); i++) { ch = name.charAt(i); if (VALID_ATTRIBUTE_CHARS.indexOf(ch) < 0) { - throw new ManifestException("Manifest attribute names must not contain '" + ch + "'"); + throw new BuildException("Manifest attribute names must not contain '" + ch + "'"); } } } diff --git a/src/tests/junit/org/apache/tools/ant/taskdefs/ManifestTest.java b/src/tests/junit/org/apache/tools/ant/taskdefs/ManifestTest.java index 5d2a48bd3..23f57c717 100644 --- a/src/tests/junit/org/apache/tools/ant/taskdefs/ManifestTest.java +++ b/src/tests/junit/org/apache/tools/ant/taskdefs/ManifestTest.java @@ -331,17 +331,27 @@ public class ManifestTest extends BuildFileTest { public void testFrom() { expectLogContaining("testFrom", Manifest.ERROR_FROM_FORBIDDEN); } - + public void testIllegalName() { - //expectBuildException("testIllegalName", "Attribute name is not valid according to the specification."); + expectBuildException("testIllegalName", "Manifest attribute names must not contain ' '"); } - + public void testIllegalNameInSection() { - //expectBuildException("testIllegalNameInSection", "Attribute name is not valid according to the specification."); + expectBuildException("testIllegalNameInSection", "Manifest attribute names must not contain ' '"); } - - - + + public void testIllegalNameBegin() { + expectBuildException("testIllegalNameInSection", "Manifest attribute names must not contain '-' at the begin."); + } + + public void testIllegalName2() { + expectBuildException("testIllegalName", "Manifest attribute names must not contain '.'"); + } + + public void testIllegalName3() { + expectBuildException("testIllegalName", "Manifest attribute names must not contain '*'"); + } + /** * Reads mftest.mf. */