[Scummvm-git-logs] scummvm master -> d38a1470196fd27cfb277788847be874b52c5e87

rvanlaar roland at rolandvanlaar.nl
Sun Aug 22 09:10:06 UTC 2021


This automated email contains information about 2 new commits which have been
pushed to the 'scummvm' repo located at https://github.com/scummvm/scummvm .

Summary:
581dd9c9d2 DEVTOOLS: COMPANION: cleanup
d38a147019 DEVTOOLS: COMPANION: improve special char handling


Commit: 581dd9c9d2c403b00e59e380f1b49e4a5136c5ca
    https://github.com/scummvm/scummvm/commit/581dd9c9d2c403b00e59e380f1b49e4a5136c5ca
Author: Roland van Laar (roland at rolandvanlaar.nl)
Date: 2021-08-22T11:10:00+02:00

Commit Message:
DEVTOOLS: COMPANION: cleanup

- Remove a superfluous import

Changed paths:
    devtools/dumper-companion.py


diff --git a/devtools/dumper-companion.py b/devtools/dumper-companion.py
index 4bed0cc289..c0b7d6753f 100755
--- a/devtools/dumper-companion.py
+++ b/devtools/dumper-companion.py
@@ -25,7 +25,6 @@ if sys.platform == "darwin":
     except ImportError:
         print("xattr is required for the 'mac' mode to work\n")
 
-from typing import ByteString
 
 # fmt: off
 decode_map = {


Commit: d38a1470196fd27cfb277788847be874b52c5e87
    https://github.com/scummvm/scummvm/commit/d38a1470196fd27cfb277788847be874b52c5e87
Author: Roland van Laar (roland at rolandvanlaar.nl)
Date: 2021-08-22T11:10:00+02:00

Commit Message:
DEVTOOLS: COMPANION: improve special char handling

We follow [1] in which chars need to be escaped.
    - we now allow the following chars in filenames: []+
    - filenames can't end in a dot or space

Includes updated tests.

[1] https://en.wikipedia.org/wiki/Filename#Reserved_characters_and_words

Changed paths:
    devtools/dumper-companion.py


diff --git a/devtools/dumper-companion.py b/devtools/dumper-companion.py
index c0b7d6753f..794a97ec37 100755
--- a/devtools/dumper-companion.py
+++ b/devtools/dumper-companion.py
@@ -167,14 +167,14 @@ def escape_string(s: str) -> str:
 
     Escape the following:
     - escape char: \x81
-    - unallowed filename chars: https://docs.microsoft.com/en-us/windows/win32/fileio/naming-a-file#naming-conventions
+    - unallowed filename chars: https://en.wikipedia.org/wiki/Filename#Reserved_characters_and_words
     - control chars < 0x20
     """
     new_name = ""
     for char in s:
         if char == "\x81":
             new_name += "\x81\x79"
-        elif char in '/":*[]+|\\?%<>,;=' or ord(char) < 0x20:
+        elif char in '/":*|\\?%<>,;=' or ord(char) < 0x20:
             new_name += "\x81" + chr(0x80 + ord(char))
         else:
             new_name += char
@@ -183,18 +183,31 @@ def escape_string(s: str) -> str:
 
 def needs_punyencoding(orig: str) -> bool:
     """
-    Filenames need punyencoding when it contains a char that should be
-    escaped.
+    A filename needs to be punyencoded when it:
+
+    - contains a char that should be escaped or
+    - ends with a dot or a space.
     """
-    return orig != escape_string(orig)
+    if orig != escape_string(orig):
+        return True
+    if orig[-1] in " .":
+        return True
+    return False
 
 
 def punyencode(orig: str) -> str:
+    """
+    Punyencode strings
+
+    - escape special characters and
+    - ensure filenames can't end in a space or dot
+    """
     s = escape_string(orig)
     encoded = s.encode("punycode").decode("ascii")
     # punyencoding adds an '-' at the end when there are no special chars
     # don't use it for comparing
-    if orig != encoded[:-1]:
+    compare = encoded[:-1]
+    if orig != compare or compare[-1] in " .":
         return "xn--" + encoded
     return orig
 
@@ -464,6 +477,8 @@ def test_encode_stdin(capsys, monkeypatch):
 def test_decode_name():
     checks = [
         ["Icon\r", "xn--Icon-ja6e"],
+        ["ends with dot .", "xn--ends with dot .-"],
+        ["ends with space ", "xn--ends with space -"],
         ["バッドデイ(Power PC)", "xn--(Power PC)-jx4ilmwb1a7h"],
     ]
     for input, expected in checks:
@@ -471,7 +486,13 @@ def test_decode_name():
 
 
 def test_needs_punyencoding():
-    checks = [["Icon\r", True], ["ascii", False], ["バッドデイ(Power PC)", False]]
+    checks = [
+        ["Icon\r", True],
+        ["ascii", False],
+        ["バッドデイ(Power PC)", False],
+        ["ends_with_dot .", True],
+        ["ends_with_space ", True],
+    ]
     for input, expected in checks:
         assert needs_punyencoding(input) == expected
 




More information about the Scummvm-git-logs mailing list