[Scummvm-git-logs] scummvm master -> 798058999d797bed8476ce5d4179bc635d08fc93

sev- sev at scummvm.org
Sun Oct 31 14:38:18 UTC 2021


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

Summary:
b9c5ef933f COMMON: Sync punycode with JS/Python code:
dfd34fc163 DEVTOOLS: COMPANION: Added one more test for encoding
798058999d TESTS: Added test for common/punycode.h


Commit: b9c5ef933fabe8b30eff5258ce0c2e5871b8439c
    https://github.com/scummvm/scummvm/commit/b9c5ef933fabe8b30eff5258ce0c2e5871b8439c
Author: Eugene Sandulenko (sev at scummvm.org)
Date: 2021-10-31T16:36:27+02:00

Commit Message:
COMMON: Sync punycode with JS/Python code:

* Allow [] in file names
* Process files ending with spaces or dots

Changed paths:
    common/punycode.cpp


diff --git a/common/punycode.cpp b/common/punycode.cpp
index ae581c5353..abdace0d5d 100644
--- a/common/punycode.cpp
+++ b/common/punycode.cpp
@@ -59,7 +59,7 @@ namespace Common {
 #define INITIAL_BIAS 72
 #define SMAX 0x10ffff // maximum Unicode code point
 
-#define SPECIAL_SYMBOLS "/\":*[]+|\\?%<>,;="
+#define SPECIAL_SYMBOLS "/\":*|\\?%<>,;="
 
 static uint32 adapt_bias(uint32 delta, unsigned n_points, int is_first) {
 	uint32 k;
@@ -78,7 +78,7 @@ static uint32 adapt_bias(uint32 delta, unsigned n_points, int is_first) {
 static char encode_digit(int c) {
 	assert(c >= 0 && c <= BASE - TMIN);
 	if (c > 25) {
-		return c + 0x30 - 26; /* '0'..'9' */
+		return c + 22; /* '0'..'9' */
 	} else {
 		return c + 0x61; /* 'a'..'z' */
 	}
@@ -144,8 +144,15 @@ String punycode_encode(const U32String &src) {
 	size_t b = h;
 
 	// If every character is ASCII, return the original string.
-	if (h == srclen)
+	if (h == srclen) {
+		// If string ends with space or dot, still punycode it
+		// because certain FSes do not support files with those
+		// endings
+		if (src[h - 1] == ' ' || src[h - 1] == '.')
+			return dst + '-';
+
 		return src;
+	}
 
 	// If we have any ASCII characters, add '-' to separate them from
 	// the non-ASCII character insertions.
@@ -205,6 +212,10 @@ bool punycode_needEncode(const String &src) {
 		}
 	}
 
+	// If name ends with space or dot, we have to encode it
+	if (src[src.size() - 1] == ' ' || src[src.size() - 1] == '.')
+		return true;
+
 	return false;
 }
 


Commit: dfd34fc163643201e13ec513ca5e0a5fbf687adc
    https://github.com/scummvm/scummvm/commit/dfd34fc163643201e13ec513ca5e0a5fbf687adc
Author: Eugene Sandulenko (sev at scummvm.org)
Date: 2021-10-31T16:37:11+02:00

Commit Message:
DEVTOOLS: COMPANION: Added one more test for encoding

Changed paths:
    devtools/dumper-companion.py


diff --git a/devtools/dumper-companion.py b/devtools/dumper-companion.py
index 1b8eabcfcc..65f94d1226 100755
--- a/devtools/dumper-companion.py
+++ b/devtools/dumper-companion.py
@@ -531,6 +531,7 @@ def test_decode_name():
         ["ends with dot .", "xn--ends with dot .-"],
         ["ends with space ", "xn--ends with space -"],
         ["バッドデイ(Power PC)", "xn--(Power PC)-jx4ilmwb1a7h"],
+        ["Hello*", "xn--Hello-la10a"],
     ]
     for input, output in checks:
         assert punyencode(input) == output


Commit: 798058999d797bed8476ce5d4179bc635d08fc93
    https://github.com/scummvm/scummvm/commit/798058999d797bed8476ce5d4179bc635d08fc93
Author: Eugene Sandulenko (sev at scummvm.org)
Date: 2021-10-31T16:37:53+02:00

Commit Message:
TESTS: Added test for common/punycode.h

Changed paths:
  A test/common/punycode.h


diff --git a/test/common/punycode.h b/test/common/punycode.h
new file mode 100644
index 0000000000..1a8ce3dc4d
--- /dev/null
+++ b/test/common/punycode.h
@@ -0,0 +1,33 @@
+#include <cxxtest/TestSuite.h>
+#include "common/punycode.h"
+
+/**
+ * Test suite for the functions in common/util.h
+ */
+static const char *strings[] = {
+	"Icon\r", "xn--Icon-ja6e", "1",
+	"ascii", "ascii", "0",
+	"ends with dot .", "xn--ends with dot .-", "1",
+	"ends with space ", "xn--ends with space -", "1",
+	"バッドデイ(Power PC)", "xn--(Power PC)-jx4ilmwb1a7h", "1",
+	"Hello*", "xn--Hello-la10a", "1",
+	0
+};
+
+class PunycodeTestSuite : public CxxTest::TestSuite {
+	public:
+
+	void test_punycode() {
+		for (const char **a = strings; *a; a += 3) {
+			Common::U32String string_in(a[0]);
+			Common::String string_out(a[1]);
+			bool need = (a[2][0] == '1');
+
+			TS_ASSERT_EQUALS(punycode_decodefilename(string_out), string_in);
+			TS_ASSERT_EQUALS(punycode_encodefilename(string_in), string_out);
+			TS_ASSERT_EQUALS(punycode_needEncode(string_in), need);
+
+			warning("'%s' -> '%s'", string_in.encode().c_str(), punycode_encodefilename(string_in).c_str());
+		}
+	}
+};




More information about the Scummvm-git-logs mailing list