changeset 98:9be628347dce

Worst thing about unix: it allows control character and newline in its filename. Added handler to ensure that shit doesn't pass through. Makes things slow but it can't be helped (tm).
author Edho Prima Arief <edho@myconan.net>
date Thu, 14 Jul 2011 01:11:18 +0700
parents 65ce115fd21d
children 97e24e89388f
files bin/recompress
diffstat 1 files changed, 5 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/bin/recompress	Thu Jul 14 00:51:44 2011 +0700
+++ b/bin/recompress	Thu Jul 14 01:11:18 2011 +0700
@@ -21,9 +21,13 @@
     current_unit += 1
   return "%.2f %s" % (outbyte, units[current_unit])
 
+def sane_fn(filename):
+  import re
+  return re.sub(r"[\x00-\x1F\x7F\n\r]", "?", filename)
+
 if __name__ == "__main__":
   for filename in sys.argv[1:]:
-    print "Recompressing %s:" % filename,
+    print "Recompressing %s:" % sane_fn(filename),
     sys.stdout.flush()
     try:
       byte_orig = os.path.getsize(filename)