You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@ant.apache.org by jh...@apache.org on 2007/04/20 07:59:52 UTC

svn commit: r530662 - /ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/ManifestTask.java

Author: jhm
Date: Thu Apr 19 22:59:51 2007
New Revision: 530662

URL: http://svn.apache.org/viewvc?view=rev&rev=530662
Log:
Check every single character instead of trying using regexp's.

Modified:
    ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/ManifestTask.java

Modified: ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/ManifestTask.java
URL: http://svn.apache.org/viewvc/ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/ManifestTask.java?view=diff&rev=530662&r1=530661&r2=530662
==============================================================================
--- ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/ManifestTask.java (original)
+++ ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/ManifestTask.java Thu Apr 19 22:59:51 2007
@@ -46,6 +46,13 @@
 public class ManifestTask extends Task {
 
     /**
+     * Specifies the valid characters which can be used in attribute names.
+     * {@value}
+     */
+    public final String VALID_ATTRIBUTE_CHARS = 
+        "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ012345679-_";
+
+    /**
      * Holds the real data.
      */
     private Manifest nestedManifest = new Manifest();
@@ -117,43 +124,39 @@
         nestedManifest.addConfiguredAttribute(attribute);
     }
 
+    /**
+     * Checks the attribute agains the Jar-specification.
+     * 
+     * Jar-Specification <i>"Name-Value pairs and Sections"</i>: <pre>
+     *   name:       alphanum *headerchar 
+     *   alphanum:   {A-Z} | {a-z} | {0-9} 
+     *   headerchar: alphanum | - | _
+     * </pre>
+     * So the resulting regexp would be <tt>[A-Za-z0-9][A-Za-z0-9-_]*</tt>.
+     * 
+     * Because of JDK 1.2 compliance and the possible absence of a
+     * regexp matcher we can not use regexps here. Instead we have to
+     * check each character.
+     * 
+     * @param attribute The attribute to check
+     * @throws ManifestException if the check fails
+     */
     private void checkAttribute(Manifest.Attribute attribute) throws ManifestException {
-        /*
-         * Jar-Specification "Name-Value pairs and Sections":
-         *   name:       alphanum *headerchar 
-         *   alphanum:   {A-Z} | {a-z} | {0-9} 
-         *   headerchar: alphanum | - | _
-         * 
-         * So the resulting regexp would be [A-Za-z0-9][A-Za-z0-9-_]*
-         */
-        String namePattern = "[A-Za-z0-9][A-Za-z0-9-_]*";
-
         String name = attribute.getName();
+        char ch = name.charAt(0);
 
-        /* FIXME Does not work for me :-( 
-        RegexpMatcherFactory factory = new RegexpMatcherFactory();
-        RegexpMatcher regexpMatcher = factory.newRegexpMatcher(getProject());
-        regexpMatcher.setPattern(namePattern);
-        if (!regexpMatcher.matches(name)) {
-            throw new ManifestException(
-                  "Attribute name is not valid according to the specification. "
-                + "(which means regexp: " + namePattern + ")" 
-            );
+        if (ch == '-' || ch == '_') {
+            throw new ManifestException("Manifest attribute names must not contain '" + ch + "'");
         }
-        */
         
-        /* Works, but not JDK 1.2 compliant 
-        if (!name.matches(namePattern)) {
-            throw new ManifestException("Attribute name is not valid according to the specification.");
-        }
-        */
-        /* */
-        if (attribute.getName().indexOf(' ') >- 1) {
-            throw new ManifestException("Manifest attribute name must not contain spaces.");
+        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 + "'");
+            }
         }
-        /* */
     }
-
+    
     /**
      * The name of the manifest file to create/update.
      * Required if used as a task.
@@ -256,5 +259,4 @@
             }
         }
     }
-
 }



---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@ant.apache.org
For additional commands, e-mail: dev-help@ant.apache.org


Re: svn commit: r530662 - /ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/ManifestTask.java

Posted by Dominique Devienne <dd...@gmail.com>.
> +        if (ch == '-' || ch == '_') {
> +            throw new ManifestException("Manifest attribute names must not contain '" + ch + "'");

"must not start with character" maybe rather than contains, since '-'
and '_' are allowed for the other caracters. Thanks, --DD

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@ant.apache.org
For additional commands, e-mail: dev-help@ant.apache.org