Commits

Zhang Huangbin committed eb95923

Delete unused translations in memory.

Comments (0)

Files changed (2)

controllers/ldap/basic.py

 
             adminLib = admin.Admin()
             cur_lang = i.get('lang', cfg.general.get('lang', 'en_US'))
-            if cur_lang is not None:
+            if cur_lang is not None and cur_lang in adminLib.getLanguageMaps().keys():
                 session['lang'] = cur_lang
 
             # Show login page.

libs/iredutils.py

     if translation is None:
         translation = get_translations(lang)
         cfg.allTranslations[lang] = translation
+
+        # Delete other translations.
+        for lk in cfg.allTranslations.keys():
+            if lk != lang:
+                del cfg.allTranslations[lk]
     return translation
 
 def ired_gettext(string):
             return (False, 'msg=PW_GREATER_THAN_MAX_LENGTH')
 
     return (True, passwd)
+
+def split_path_safely(path):
+    """Splits up a path into individual components.  If one of the
+    components is unsafe on the file system, `None` is returned:
+
+    >>> split_path_safely("foo/bar/baz")
+    ['foo', 'bar', 'baz']
+    >>> split_path_safely("foo/bar/baz/../meh")
+    >>> split_path_safely("/meh/muh")
+    ['meh', 'muh']
+    >>> split_path_safely("/blafasel/.muh")
+    ['blafasel', '.muh']
+    >>> split_path_safely("/blafasel/./x")
+    ['blafasel', 'x']
+    """
+    pieces = []
+    for piece in path.split('/'):
+        if path.sep in piece \
+           or (path.altsep and path.altsep in piece) or \
+           piece == path.pardir:
+            return None
+        elif piece and piece != '.':
+            pieces.append(piece)
+    return pieces