You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ace.apache.org by ma...@apache.org on 2015/06/05 23:48:58 UTC

svn commit: r1683872 - /ace/trunk/org.apache.ace.client.repository/src/org/apache/ace/client/repository/impl/RepositoryObjectImpl.java

Author: marrs
Date: Fri Jun  5 21:48:58 2015
New Revision: 1683872

URL: http://svn.apache.org/r1683872
Log:
ACE-518 Added validation to keys for attributes and tags.

Modified:
    ace/trunk/org.apache.ace.client.repository/src/org/apache/ace/client/repository/impl/RepositoryObjectImpl.java

Modified: ace/trunk/org.apache.ace.client.repository/src/org/apache/ace/client/repository/impl/RepositoryObjectImpl.java
URL: http://svn.apache.org/viewvc/ace/trunk/org.apache.ace.client.repository/src/org/apache/ace/client/repository/impl/RepositoryObjectImpl.java?rev=1683872&r1=1683871&r2=1683872&view=diff
==============================================================================
--- ace/trunk/org.apache.ace.client.repository/src/org/apache/ace/client/repository/impl/RepositoryObjectImpl.java (original)
+++ ace/trunk/org.apache.ace.client.repository/src/org/apache/ace/client/repository/impl/RepositoryObjectImpl.java Fri Jun  5 21:48:58 2015
@@ -30,6 +30,7 @@ import java.util.List;
 import java.util.Map;
 import java.util.Properties;
 import java.util.Set;
+import java.util.regex.Pattern;
 
 import org.apache.ace.client.repository.Associatable;
 import org.apache.ace.client.repository.Association;
@@ -55,6 +56,7 @@ public class RepositoryObjectImpl<T exte
     private final Map<Class, List<Association>> m_associations = new HashMap<Class, List<Association>>();
     private final ChangeNotifier m_notifier;
     private final String m_xmlNode;
+    private static final Pattern VALID_KEY_PATTERN = Pattern.compile("[a-zA-Z]([a-zA-Z0-9_:.-])*");
 
     private volatile boolean m_deleted = false;
     private volatile boolean m_busy = false;
@@ -189,6 +191,7 @@ public class RepositoryObjectImpl<T exte
         if (value == null || key == null) {
             throw new IllegalArgumentException("Invalid key/value pair: " + key + "/" + value);
         }
+        validateKey(key);
         for (String s : getDefiningKeys()) {
             if (s.equals(key)) {
                 throw new UnsupportedOperationException("The defining attribute " + key + " is not allowed to be changed.");
@@ -235,6 +238,7 @@ public class RepositoryObjectImpl<T exte
         if (value == null || key == null) {
             throw new IllegalArgumentException("Invalid key/value pair: " + key + "/" + value);
         }
+        validateKey(key);
         String result = null;
         synchronized (m_attributes) {
             ensureCurrent();
@@ -249,6 +253,12 @@ public class RepositoryObjectImpl<T exte
         return result;
     }
 
+    private void validateKey(String key) {
+        if (!VALID_KEY_PATTERN.matcher(key).matches()) {
+            throw new IllegalArgumentException("Invalid key " + key + " does not match regex pattern " + VALID_KEY_PATTERN.pattern());
+        }
+    }
+
     @Override
     public String removeTag(String key) {
         String result = null;