Browse Source

[php] replace Italian file name escaping with a real one

Simon Krajewski 10 years ago
parent
commit
09aa0bae3e
4 changed files with 19 additions and 20 deletions
  1. 1 5
      genphp.ml
  2. 5 2
      std/php/_std/haxe/Resource.hx
  3. 2 2
      tests/unit/compile-each.hxml
  4. 11 11
      tests/unit/src/unit/TestResource.hx

+ 1 - 5
genphp.ml

@@ -332,14 +332,10 @@ let create_directory com ldir =
  	(List.iter (fun p -> atm_path := !atm_path ^ "/" ^ p; if not (Sys.file_exists !atm_path) then (Unix.mkdir !atm_path 0o755);) ldir)
  	(List.iter (fun p -> atm_path := !atm_path ^ "/" ^ p; if not (Sys.file_exists !atm_path) then (Unix.mkdir !atm_path 0o755);) ldir)
 
 
 let write_resource dir name data =
 let write_resource dir name data =
-	let i = ref 0 in
-	String.iter (fun c ->
-		if c = '\\' || c = '/' || c = ':' || c = '*' || c = '?' || c = '"' || c = '<' || c = '>' || c = '|' then String.blit "_" 0 name !i 1;
-		incr i
-	) name;
 	let rdir = dir ^ "/res" in
 	let rdir = dir ^ "/res" in
 	if not (Sys.file_exists dir) then Unix.mkdir dir 0o755;
 	if not (Sys.file_exists dir) then Unix.mkdir dir 0o755;
 	if not (Sys.file_exists rdir) then Unix.mkdir rdir 0o755;
 	if not (Sys.file_exists rdir) then Unix.mkdir rdir 0o755;
+	let name = Base64.str_encode name in
 	let ch = open_out_bin (rdir ^ "/" ^ name) in
 	let ch = open_out_bin (rdir ^ "/" ^ name) in
 	output_string ch data;
 	output_string ch data;
 	close_out ch
 	close_out ch

+ 5 - 2
std/php/_std/haxe/Resource.hx

@@ -21,6 +21,9 @@
  */
  */
 package haxe;
 package haxe;
 
 
+import haxe.io.Bytes;
+import haxe.crypto.Base64;
+
 @:coreApi
 @:coreApi
 class Resource {
 class Resource {
 
 
@@ -33,14 +36,14 @@ class Resource {
 	}
 	}
 
 
 	static function getPath(name : String) : String {
 	static function getPath(name : String) : String {
-		return getDir()+'/'+cleanName(name);
+		return getDir()+'/'+Base64.encode(Bytes.ofString(name));
 	}
 	}
 
 
 	public static function listNames() : Array<String> {
 	public static function listNames() : Array<String> {
 		var a = sys.FileSystem.readDirectory(getDir());
 		var a = sys.FileSystem.readDirectory(getDir());
 		if(a[0] == '.') a.shift();
 		if(a[0] == '.') a.shift();
 		if(a[0] == '..') a.shift();
 		if(a[0] == '..') a.shift();
-		return a;
+		return a.map(function(s) return Base64.decode(s).toString());
 	}
 	}
 
 
 	public static function getString( name : String ) : String {
 	public static function getString( name : String ) : String {

+ 2 - 2
tests/unit/compile-each.hxml

@@ -2,7 +2,7 @@
 -debug
 -debug
 -cp src
 -cp src
 -cp "C:\Program Files\The Haxe Effect\src/dev/null"
 -cp "C:\Program Files\The Haxe Effect\src/dev/null"
--resource res1.txt@res?!%[]))("'£1.txt
--resource res2.bin@res?!%[]))("'£1.bin
+-resource res1.txt@res?!%[]))("'1.txt
+-resource res2.bin@res?!%[]))("'1.bin
 -dce full
 -dce full
 -D analyzer
 -D analyzer

+ 11 - 11
tests/unit/src/unit/TestResource.hx

@@ -7,22 +7,22 @@ class TestResource extends Test {
 	function testResources() {
 	function testResources() {
 		var names = haxe.Resource.listNames();
 		var names = haxe.Resource.listNames();
 		eq( names.length, 2 );
 		eq( names.length, 2 );
-		if( names[0] == "res?!%[]))(\"'£1.txt" )
-			eq( names[1], "res?!%[]))(\"'£1.bin" );
+		if( names[0] == "res?!%[]))(\"'1.txt" )
+			eq( names[1], "res?!%[]))(\"'1.bin" );
 		else {
 		else {
-			eq( names[0], "res?!%[]))(\"'£1.bin" );
-			eq( names[1], "res?!%[]))(\"'£1.txt" );
+			eq( names[0], "res?!%[]))(\"'1.bin" );
+			eq( names[1], "res?!%[]))(\"'1.txt" );
 		}
 		}
-		eq( haxe.Resource.getString("res?!%[]))(\"'£1.txt"), STR );
+		eq( haxe.Resource.getString("res?!%[]))(\"'1.txt"), STR );
 		#if (neko || php)
 		#if (neko || php)
 		// allow binary strings
 		// allow binary strings
-		eq( haxe.Resource.getBytes("res?!%[]))(\"'£1.bin").sub(0,9).toString(), "MZ\x90\x00\x03\x00\x00\x00\x04" );
+		eq( haxe.Resource.getBytes("res?!%[]))(\"'1.bin").sub(0,9).toString(), "MZ\x90\x00\x03\x00\x00\x00\x04" );
 		#else
 		#else
 		// cut until first \0
 		// cut until first \0
-		eq( haxe.Resource.getString("res?!%[]))(\"'£1.bin").substr(0,2), "MZ" );
+		eq( haxe.Resource.getString("res?!%[]))(\"'1.bin").substr(0,2), "MZ" );
 		#end
 		#end
-		eq( haxe.Resource.getBytes("res?!%[]))(\"'£1.txt").compare(haxe.io.Bytes.ofString(STR)), 0 );
-		var b = haxe.Resource.getBytes("res?!%[]))(\"'£1.bin");
+		eq( haxe.Resource.getBytes("res?!%[]))(\"'1.txt").compare(haxe.io.Bytes.ofString(STR)), 0 );
+		var b = haxe.Resource.getBytes("res?!%[]))(\"'1.bin");
 		var firsts = [0x4D,0x5A,0x90,0x00,0x03,0x00,0x00,0x00,0x04,0x00,0x00,0x00,0xFF,0xFF,0x00,0x00,0xB8];
 		var firsts = [0x4D,0x5A,0x90,0x00,0x03,0x00,0x00,0x00,0x04,0x00,0x00,0x00,0xFF,0xFF,0x00,0x00,0xB8];
 		var lasts = [0xD6,0x52,0x03,0x1A,0x2C,0x4E,0x45,0x4B,0x4F,0x00,0x1C,0x00,0x00];
 		var lasts = [0xD6,0x52,0x03,0x1A,0x2C,0x4E,0x45,0x4B,0x4F,0x00,0x1C,0x00,0x00];
 		for( i in 0...firsts.length )
 		for( i in 0...firsts.length )
@@ -33,10 +33,10 @@ class TestResource extends Test {
 
 
 	#if neko
 	#if neko
 	static function main() {
 	static function main() {
-		var ch = sys.io.File.write("res?!%[]))(\"'£1.txt",true);
+		var ch = sys.io.File.write("res?!%[]))(\"'1.txt",true);
 		ch.writeString(STR);
 		ch.writeString(STR);
 		ch.close();
 		ch.close();
-		var ch = sys.io.File.write("res?!%[]))(\"'£1.bin",true);
+		var ch = sys.io.File.write("res?!%[]))(\"'1.bin",true);
 		ch.writeString("Héllo");
 		ch.writeString("Héllo");
 		ch.writeByte(0);
 		ch.writeByte(0);
 		ch.writeString("World");
 		ch.writeString("World");