Simon Meers avatar Simon Meers committed ea153a9

Always remove carriage returns.

Comments (0)

Files changed (1)


         if attr.find(separator) > 0:
             bits = attr.split(separator)
-            return recursive_getattr(getattr(obj, bits[0]), 
+            return recursive_getattr(getattr(obj, bits[0]),
                                      separator.join(bits[1:]), default)
             return getattr(obj, attr)
     if options.parent:
         parent_model = \
-        queryset = build_queryset(parent_model, queryset, 
+        queryset = build_queryset(parent_model, queryset,
     return queryset
         path = os.path.join(model._meta.app_label,model._meta.module_name)
     return os.path.join(path, options.get_path_identifier(obj))
+def sanitise_message(message):
+    """ Prepare message for storage in .po file. """
+    # carriage returns are forbidden in po files, but seem to be ignored
+    # during lookups, so it should be safe to remove them
+    return message.replace('\r', '')
 class Command(NoArgsCommand):
     """ dbgettext_export management command """
         # remove any old files
         if os.path.exists(root):
-            rmtree(root) 
+            rmtree(root)
         # for each registered model:
         for model, options in registry._registry.items():
             for obj in build_queryset(model):
                 path = os.path.join(root, build_path(obj))
-                if not os.path.exists(path): 
+                if not os.path.exists(path):
                 for attr_name in options.attributes:
                     attr = get_field_or_callable_content(obj, attr_name)
                     if attr:
                         f = open(os.path.join(path, '' % attr_name), 'w')
-                        write(f, attr)
+                        write(f, sanitise_message(attr))
                 for attr_name in options.parsed_attributes:
                     f = open(os.path.join(path, '' % attr_name), 'w')
                     for s in parsed_gettext(obj, attr_name, export=True):
-                        write(f, s)
-                    f.close()                    
+                        write(f, sanitise_message(s))
+                    f.close()
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.