[vlma-devel] commit: Improve server name validation. (Adrien Grand )

git version control git at videolan.org
Mon Apr 28 17:45:27 CEST 2008


vlma | branch: master | Adrien Grand <jpountz at videolan.org> | Mon Apr 28 17:40:01 2008 +0200| [0d6b6e9ee80723c24cab6f572aa8245d8f9b039d]

Improve server name validation.

> http://git.videolan.org/gitweb.cgi/vlma.git/?a=commit;h=0d6b6e9ee80723c24cab6f572aa8245d8f9b039d
---

 .../vlma/web/servers/ServersAddValidator.java      |   20 +++++++++++++++++++-
 1 files changed, 19 insertions(+), 1 deletions(-)

diff --git a/web/src/main/java/org/videolan/vlma/web/servers/ServersAddValidator.java b/web/src/main/java/org/videolan/vlma/web/servers/ServersAddValidator.java
index c387b00..7d498e8 100644
--- a/web/src/main/java/org/videolan/vlma/web/servers/ServersAddValidator.java
+++ b/web/src/main/java/org/videolan/vlma/web/servers/ServersAddValidator.java
@@ -35,6 +35,24 @@ public class ServersAddValidator implements Validator {
         return arg0.equals(ServersAdd.class);
     }
 
+    private static boolean validateName(String s) {
+        if (s == null) return false;
+        int index = 0;
+        while (index < s.length()) {
+            char c = s.charAt(index);
+            if ((c >= 'a' && c <= 'z') ||
+                (c >= 'A' && c <= 'Z') ||
+                (c >= '0' && c <= '9') ||
+                (c == '-' || c == '_')) {
+                index++;
+            } else {
+                System.out.println(c);
+                return false;
+            }
+        }
+        return true;
+    }
+
     public void validate(Object arg0, Errors arg1) {
         ServersAdd serversAdd = (ServersAdd) arg0;
 
@@ -42,7 +60,7 @@ public class ServersAddValidator implements Validator {
             arg1.rejectValue("name", "servers.add.error.not-specified");
             return;
         } else {
-            if ("".equals(serversAdd.getName())) {
+            if (!validateName(serversAdd.getName())) {
                 arg1.rejectValue("name", "servers.add.error.invalidname");
                 return;
             }



More information about the vlma-devel mailing list