]> git.lizzy.rs Git - nhentai.git/commitdiff
fix issue #186
authoratsushi-hirako <65751437+atsushi-hirako@users.noreply.github.com>
Fri, 1 Jan 2021 11:11:09 +0000 (20:11 +0900)
committerGitHub <noreply@github.com>
Fri, 1 Jan 2021 11:11:09 +0000 (20:11 +0900)
change to blacklist approach (allow 2-bytes character)

nhentai/utils.py

index b3358e461fcc774224f0fa1844448204999cef1b..1ee6e7e485f680b5697911dead207015b01e9829 100644 (file)
@@ -227,19 +227,15 @@ def generate_pdf(output_dir='.', doujinshi_obj=None, rm_origin_dir=False):
 
 
 def format_filename(s):
-    """Take a string and return a valid filename constructed from the string.
-Uses a whitelist approach: any characters not present in valid_chars are
-removed. Also spaces are replaced with underscores.
-
-Note: this method may produce invalid filenames such as ``, `.` or `..`
-When I use this method I prepend a date string like '2009_01_15_19_46_32_'
-and append a file extension like '.txt', so I avoid the potential of using
-an invalid filename.
-
-"""
+    """
+    It used to be a whitelist approach allowed only alphabet and a part of symbols.
+    but most doujinshi's names include Japanese 2-byte characters and these was rejected.
+    so it is using blacklist approach now.
+    if filename include forbidden characters (\'/:,;*?"<>|) ,it replace space character(' '). 
+    """
     # maybe you can use `--format` to select a suitable filename
-    valid_chars = "-_.()[] %s%s" % (string.ascii_letters, string.digits)
-    filename = ''.join(c for c in s if c in valid_chars)
+    ban_chars = '\\\'/:,;*?"<>|'
+    filename = s.translate(str.maketrans(ban_chars, ' '*len(ban_chars)))
     if len(filename) > 100:
         filename = filename[:100] + '...]'