r404 - trunk/scripts

DONOTREPLY at icculus.org DONOTREPLY at icculus.org
Sat Jan 12 07:47:19 EST 2008


Author: icculus
Date: 2008-01-12 07:47:19 -0500 (Sat, 12 Jan 2008)
New Revision: 404

Modified:
   trunk/scripts/mojosetup_init.lua
Log:
Make sure all translation formatting strings are sane at startup.


Modified: trunk/scripts/mojosetup_init.lua
===================================================================
--- trunk/scripts/mojosetup_init.lua	2008-01-12 12:46:51 UTC (rev 403)
+++ trunk/scripts/mojosetup_init.lua	2008-01-12 12:47:19 UTC (rev 404)
@@ -89,6 +89,39 @@
 -- This table gets filled by the config file. Just create an empty one for now.
 MojoSetup.installs = {}
 
+
+local function sanity_check_localization_entry(str, translations)
+    local maxval = -1;
+
+    for val in string.gmatch(str, "%%.") do
+        val = string.sub(val, 2)
+        if string.match(val, "^[^%%0-9]$") ~= nil then
+            MojoSetup.fatal("BUG: localization key ['" .. str .. "'] has invalid escape sequence.")
+        end
+        if val ~= "%" then
+            local num = tonumber(val)
+            if num > maxval then
+                maxval = num
+            end
+        end
+    end
+
+    for k,v in pairs(translations) do
+        for val in string.gmatch(v, "%%.") do
+            val = string.sub(val, 2)
+            if string.match(val, "^[^%%0-9]$") ~= nil then
+                MojoSetup.fatal("BUG: '" .. k .. "' localization ['" .. v .. "'] has invalid escape sequence.")
+            end
+            if val ~= "%" then
+                if tonumber(val) > maxval then
+                    MojoSetup.fatal("BUG: '" .. k .. "' localization ['" .. v .. "'] has escape sequence > max for translation.")
+                end
+            end
+        end
+    end
+end
+
+
 -- Build the translations table from the localizations table supplied in
 --  localizations.lua...
 if type(MojoSetup.localization) ~= "table" then
@@ -102,6 +135,7 @@
     MojoSetup.translations = {}
     for k,v in pairs(MojoSetup.localization) do
         if type(v) == "table" then
+            sanity_check_localization_entry(k, v)
             if v[locale] ~= nil then
                 MojoSetup.translations[k] = v[locale]
                 at_least_one = true




More information about the mojosetup-commits mailing list