[easytag] Replace illegal characters at end of filename



commit b3504c69bb11cfd800993a443d0c1be1124c2966
Author: David King <amigadave amigadave com>
Date:   Tue Jan 5 16:00:29 2016 +0000

    Replace illegal characters at end of filename
    
    On FAT filesystems, filenames should avoid ending with ' ' or '.':
    
    https://msdn.microsoft.com/en-us/library/windows/desktop/aa365247%28v=vs.85%29.aspx#naming_conventions
    
    Handle this in et_filename_prepare(), when the option to replace illegal
    characters in filenames is enabled, and add new test cases.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=760155

 src/misc.c        |   11 +++++++++++
 tests/test-misc.c |    4 +++-
 2 files changed, 14 insertions(+), 1 deletions(-)
---
diff --git a/src/misc.c b/src/misc.c
index 027ec4f..3c41d5c 100644
--- a/src/misc.c
+++ b/src/misc.c
@@ -527,6 +527,8 @@ et_filename_prepare (gchar *filename_utf8,
      * Joliet (CD-ROM filesystems). */
     if (replace_illegal)
     {
+        size_t last;
+
         // Commented as we display unicode values as "\351" for "é"
         //while ( (character=g_utf8_strchr(filename_utf8, -1, '\\'))!=NULL )
         //    *character = ',';
@@ -546,6 +548,15 @@ et_filename_prepare (gchar *filename_utf8,
             *character = ')';
         while ( (character=g_utf8_strchr(filename_utf8, -1, '|'))!=NULL )
             *character = '-';
+
+        /* FAT has additional restrictions on the last character of a filename.
+         * 
https://msdn.microsoft.com/en-us/library/windows/desktop/aa365247%28v=vs.85%29.aspx#naming_conventions */
+        last = strlen (filename_utf8) - 1;
+
+        if (filename_utf8[last] == ' ' || filename_utf8[last] == '.')
+        {
+            filename_utf8[last] = '_';
+        }
     }
 }
 
diff --git a/tests/test-misc.c b/tests/test-misc.c
index bf13933..724dd33 100644
--- a/tests/test-misc.c
+++ b/tests/test-misc.c
@@ -73,7 +73,9 @@ misc_filename_prepare (void)
         { "foo<bar", "foo(bar", "foo<bar" },
         { "foo>bar", "foo)bar", "foo>bar" },
         { "foo|bar", "foo-bar", "foo|bar" },
-        { "foo|bar*baz", "foo-bar+baz", "foo|bar*baz" }
+        { "foo|bar*baz", "foo-bar+baz", "foo|bar*baz" },
+        { "foo.", "foo_", "foo." },
+        { "foo ", "foo_", "foo " }
         /* TODO: Add more tests. */
     };
 


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