[libgames-support] scores: Add input validation for category keys



commit bd7b0b93b7fb2275d0e7cc059f308cfa643d7d7e
Author: Michael Catanzaro <mcatanzaro igalia com>
Date:   Fri Feb 12 22:16:27 2016 -0600

    scores: Add input validation for category keys

 games/scores/category.vala |   19 ++++++++++++++++++-
 1 files changed, 18 insertions(+), 1 deletions(-)
---
diff --git a/games/scores/category.vala b/games/scores/category.vala
index cdcf802..987ffc6 100644
--- a/games/scores/category.vala
+++ b/games/scores/category.vala
@@ -23,7 +23,24 @@ namespace Scores {
 
 public class Category : Object
 {
-    public string key { get; set; }
+    private string _key;
+    public string key
+    {
+        get { return _key; }
+        set
+        {
+            for (int i = 0; value[i] != '\0'; i++)
+            {
+                if (!value[i].isalnum () && value[i] != '-')
+                {
+                    error ("Category keys may contain only hyphens and alphanumeric characters.");
+                }
+            }
+            _key = value;
+        }
+    }
+
+    /* This is a user-friendly name. It should be marked for translation. */
     public string name { get; set; }
 
     public Category (string key, string name)


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]