Commits

Ron DuPlain committed 440e06b

Be consistent with os.path in lowercase_ext.

Comments (0)

Files changed (2)

 
 
 def lowercase_ext(filename):
+    """
+    This is a helper used by UploadSet.save to provide lowercase extensions for
+    all processed files, to compare with configured extensions in the same
+    case.
+
+    .. versionchanged:: 0.1.4
+       Filenames without extensions are no longer lowercased, only the
+       extension is returned in lowercase, if an extension exists.
+
+    :param filename: The filename to ensure has a lowercase extension.
+    """
     if '.' in filename:
         main, ext = os.path.splitext(filename)
         return main + ext.lower()
-    else:
-        return filename.lower()
+    # For consistency with os.path.splitext,
+    # do not treat a filename without an extension as an extension.
+    # That is, do not return filename.lower().
+    return filename
 
 
 def addslash(url):

tests/test-uploads.py

 import os.path
 from flask import Flask, url_for
 from flaskext.uploads import (UploadSet, UploadConfiguration, extension,
-    TestingFileStorage, patch_request_class, configure_uploads, addslash,
-    ALL, AllExcept)
+    lowercase_ext, TestingFileStorage, patch_request_class, configure_uploads,
+    addslash, ALL, AllExcept)
 
 
 class TestMiscellaneous(object):
         assert extension('archive.tar.gz') == 'gz'
         assert extension('audio.m4a') == 'm4a'
 
+    def test_lowercase_ext(self):
+        assert lowercase_ext('foo.txt') == 'foo.txt'
+        assert lowercase_ext('FOO.TXT') == 'FOO.txt'
+        assert lowercase_ext('foo') == 'foo'
+        assert lowercase_ext('FOO') == 'FOO'
+        assert lowercase_ext('archive.tar.gz') == 'archive.tar.gz'
+        assert lowercase_ext('ARCHIVE.TAR.GZ') == 'ARCHIVE.TAR.gz'
+        assert lowercase_ext('audio.m4a') == 'audio.m4a'
+        assert lowercase_ext('AUDIO.M4A') == 'AUDIO.m4a'
+
     def test_addslash(self):
         assert (addslash('http://localhost:4000') ==
                 'http://localhost:4000/')