diff --git a/_test/cases/inc/safefn.test.php b/_test/cases/inc/safefn.test.php index c789875bab78727ccc768fbcb9f52a592d5a7a78..1227e55783dbf38c37c3785c81787cb752dc5457 100644 --- a/_test/cases/inc/safefn.test.php +++ b/_test/cases/inc/safefn.test.php @@ -10,19 +10,23 @@ class safeFN_test extends UnitTestCase { function test1(){ // we test multiple cases here - format: string, repl, additional, test $tests = array(); - $tests[] = array('äa.txt', '%5g.a.txt'); - $tests[] = array('ä.', '%5g..'); + $tests[] = array('äa.txt', '%5g]a.txt'); + $tests[] = array('ä.', '%5g].'); $tests[] = array('asciistring','asciistring'); $tests[] = array('ascii-_/.string','ascii-_/.string'); - $tests[] = array('AName','%x%1a.ame'); - $tests[] = array('A Name','%x%0%1a.ame'); - $tests[] = array('Another...Name','%x.nother...%1a.ame'); - $tests[] = array('Aß∂ƒName','%x%5b%6oy%aa%1a.ame'); - $tests[] = array('A%ß-∂_.Æ’Name','%x%%5b.-%6oy._.%aa%1a.ame'); - $tests[] = array('A%%ß-∂_.Æ’Name','%x%%%5b.-%6oy._.%aa%1a.ame'); - $tests[] = array('ë°ì´í„°ë„ 함께 ë³µì›ë©ë‹ˆë‹¤. ê°•ë ¥í•œ','%zf4%13dg%15ao%zhg%0%164o%yig%0%11at%138w%zk9%zag%zb8..%0%xyt%10cl%164c.'); - $tests[] = array('ÑовмеÑтимаÑ','%td%ta%sy%t8%t1%td%te%t4%t8%sw%tr.'); - $tests[] = array('нехватка_файлового_проÑтранÑтва_на_Ñервере_p0-squid.some.domain.1270211897.txt.gz','%t9%t1%th%sy%sw%te%t6%sw._%tg%sw%t5%t7%ta%sy%ta%sz%ta._%tb%tc%ta%td%te%tc%sw%t9%td%te%sy%sw._%t9%sw._%td%t1%tc%sy%t1%tc%t1._p0-squid.some.domain.1270211897.txt.gz'); + $tests[] = array('AName','%x%1a]ame'); + $tests[] = array('A Name','%x%0%1a]ame'); + $tests[] = array('Another...Name','%x]nother...%1a]ame'); + $tests[] = array('Aß∂ƒName','%x%5b%6oy%aa%1a]ame'); + $tests[] = array('A%ß-∂_.Æ’Name','%x%%5b]-%6oy]_.%aa%1a]ame'); + $tests[] = array('A%%ß-∂_.Æ’Name','%x%%%5b]-%6oy]_.%aa%1a]ame'); + $tests[] = array('ë°ì´í„°ë„ 함께 ë³µì›ë©ë‹ˆë‹¤. ê°•ë ¥í•œ','%zf4%13dg%15ao%zhg%0%164o%yig%0%11at%138w%zk9%zag%zb8].%0%xyt%10cl%164c]'); + $tests[] = array('ÑовмеÑтимаÑ','%td%ta%sy%t8%t1%td%te%t4%t8%sw%tr]'); + $tests[] = array('нехватка_файлового_проÑтранÑтва_на_Ñервере_p0-squid.some.domain.1270211897.txt.gz','%t9%t1%th%sy%sw%te%t6%sw]_%tg%sw%t5%t7%ta%sy%ta%sz%ta]_%tb%tc%ta%td%te%tc%sw%t9%td%te%sy%sw]_%t9%sw]_%td%t1%tc%sy%t1%tc%t1]_p0-squid.some.domain.1270211897.txt.gz'); + + $tests[] = array('name[1]','name[1]'); + $tests[] = array('Name[1]','%1a]ame[1]'); + $tests[] = array('Name[A]','%1a]ame[%x]]'); foreach($tests as $test){ list($utf8,$safe) = $test; @@ -30,6 +34,15 @@ class safeFN_test extends UnitTestCase { $this->assertEqual(SafeFN::decode($safe),$utf8); } } + + function test2(){ + $tests[] = array('ÑовмеÑтимаÑ','%td%ta%sy%t8%t1%td%te%t4%t8%sw%tr'); + + foreach($tests as $test){ + list($utf8,$safe) = $test; + $this->assertEqual(SafeFN::decode($safe),$utf8); + } + } } //Setup VIM: ex: et ts=4 : diff --git a/inc/SafeFN.class.php b/inc/SafeFN.class.php index ac6698a63114913c8684fa788aec4bbcef60d750..43b19e9abf0c6e1332b51bb8d6a94b683a251ef6 100644 --- a/inc/SafeFN.class.php +++ b/inc/SafeFN.class.php @@ -16,9 +16,9 @@ class SafeFN { // 'safe' characters are a superset of $plain, $pre_indicator and $post_indicator - private static $plain = '-/_0123456789abcdefghijklmnopqrstuvwxyz'; // these characters aren't converted + private static $plain = '-./[_0123456789abcdefghijklmnopqrstuvwxyz'; // these characters aren't converted private static $pre_indicator = '%'; - private static $post_indicator = '.'; + private static $post_indicator = ']'; /** * Convert an UTF-8 string to a safe ASCII String @@ -37,7 +37,7 @@ class SafeFN { * - reduce codepoint value for non-printable ASCII characters (0x00 - 0x1f). Space becomes our zero. * - convert reduced value to base36 (0-9a-z) * - append $pre_indicator characater followed by base36 string to output, set converted flag - * continue to next character) + * (continue to next character) * * @param string $filename a utf8 string, should only include printable characters - not 0x00-0x1f * @return string an encoded representation of $filename using only 'safe' ASCII characters