@@ 27-55 (lines=29) @@ | ||
24 | return $result; |
|
25 | } |
|
26 | ||
27 | function path_unescape($path) { |
|
28 | $result = ""; |
|
29 | if ($path) { |
|
30 | debug("path_unescape: escaped path: $path"); |
|
31 | $result = preg_replace_callback( |
|
32 | '/(_[0-9a-fA-F][0-9a-fA-F]|__)/', |
|
33 | function( $matches ) { |
|
34 | // Two types of escaped characters can be here, the |
|
35 | // underscore or other characters. Check for the |
|
36 | // underscore first. |
|
37 | ||
38 | $char = $matches[0]; |
|
39 | if ($char[1] == "_") { |
|
40 | // It is the underscore, return it as a character. |
|
41 | return "_"; |
|
42 | } |
|
43 | ||
44 | // Assume it is an escaped character here. Find the |
|
45 | // numbers in hex, turn them back to decimal, get |
|
46 | // the corresponding character and return it. |
|
47 | ||
48 | return chr(hexdec(substr($char, 1, 2))); |
|
49 | }, |
|
50 | $path |
|
51 | ); |
|
52 | } |
|
53 | debug("path_unescape: unescaped path: $result"); |
|
54 | return $result; |
|
55 | } |
|
56 | ||
57 | ||
58 | function path_escape($path) { |
|
@@ 58-85 (lines=28) @@ | ||
55 | } |
|
56 | ||
57 | ||
58 | function path_escape($path) { |
|
59 | // This function will return an escaped path. All the characters not supported by Ariadne will be encoded. |
|
60 | // See also path_escape_callback |
|
61 | ||
62 | // Returns an empty string if no path, or an empty path was given. |
|
63 | $result = ""; |
|
64 | if ($path) { |
|
65 | debug("path_escape:files unescaped path: $path"); |
|
66 | $result = preg_replace_callback( |
|
67 | '/[^\/A-Za-z0-9.-]/', |
|
68 | function ( $char ) { |
|
69 | // Replaces characters in the path with their number. |
|
70 | // Quite similar to " " -> "%20" for HTML escape, but we use _ instead of % |
|
71 | // This function is to be used as a callback for preg_replace_callback |
|
72 | if ($char[0]) { |
|
73 | if ($char[0]=="_") { |
|
74 | return "__"; |
|
75 | } else { |
|
76 | return "_".dechex(ord($char[0])); |
|
77 | } |
|
78 | } |
|
79 | }, |
|
80 | $path |
|
81 | ); |
|
82 | } |
|
83 | debug("path_escaspe:files escaped path: $result"); |
|
84 | return $result; |
|
85 | } |
|
86 | } |
|
87 | ||
88 | class pinp_util extends util { |
@@ 22-50 (lines=29) @@ | ||
19 | debug("webdav: init done"); |
|
20 | } |
|
21 | ||
22 | function path_unescape($path) { |
|
23 | $result = ""; |
|
24 | if ($path) { |
|
25 | debug("webdav: escaped path: $path"); |
|
26 | $result = preg_replace_callback( |
|
27 | '/(_[0-9a-fA-F][0-9a-fA-F]|__)/', |
|
28 | function ( $matches ) { |
|
29 | // Two types of escaped characters can be here, the |
|
30 | // underscore or other characters. Check for the |
|
31 | // underscore first. |
|
32 | ||
33 | $char = $matches[0]; |
|
34 | if ($char[1] == "_") { |
|
35 | // It is the underscore, return it as a character. |
|
36 | return "_"; |
|
37 | } |
|
38 | ||
39 | // Assume it is an escaped character here. Find the |
|
40 | // numbers in hex, turn them back to decimal, get |
|
41 | // the corresponding character and return it. |
|
42 | ||
43 | return chr(hexdec(substr($char, 1, 2))); |
|
44 | }, |
|
45 | $path |
|
46 | ); |
|
47 | } |
|
48 | debug("webdav: unescaped path: $result"); |
|
49 | return $result; |
|
50 | } |
|
51 | ||
52 | public static function path_unescape_callback($char) { |
|
53 | // Two types of escaped characters can be here, the |
@@ 24-48 (lines=25) @@ | ||
21 | } |
|
22 | } |
|
23 | ||
24 | function path_escape($path) { |
|
25 | // This function will return an escaped path. All the characters not supported by Ariadne will be encoded. |
|
26 | // See also path_escape_callback |
|
27 | ||
28 | // Returns an empty string if no path, or an empty path was given. |
|
29 | $result = ""; |
|
30 | if ($path) { |
|
31 | debug("webdav:files unescaped path: $path"); |
|
32 | $result = preg_replace_callback( |
|
33 | '/[^\/A-Za-z0-9.-]/', |
|
34 | function( $char ) { |
|
35 | if ($char[0]) { |
|
36 | if ($char[0]=="_") { |
|
37 | return "__"; |
|
38 | } else { |
|
39 | return "_".dechex(ord($char[0])); |
|
40 | } |
|
41 | } |
|
42 | }, |
|
43 | $path |
|
44 | ); |
|
45 | } |
|
46 | debug("webdav:files escaped path: $result"); |
|
47 | return $result; |
|
48 | } |
|
49 | ||
50 | function make_path($curr_dir, $path) { |
|
51 | debug("webdav:files:make_path($curr_dir, $path)"); |