File tree Expand file tree Collapse file tree 2 files changed +42
-0
lines changed Expand file tree Collapse file tree 2 files changed +42
-0
lines changed Original file line number Diff line number Diff line change 2929 },
3030 "files" : [
3131 " src/WordPress/Blueprints/functions.php" ,
32+ " src/WordPress/Filesystem/functions.php" ,
3233 " src/WordPress/Streams/stream_str_replace.php"
3334 ]
3435 },
Original file line number Diff line number Diff line change 1+ <?php
2+
3+ function wp_join_paths () {
4+ $ paths = array ();
5+ foreach ( func_get_args () as $ arg ) {
6+ if ( $ arg !== '' ) {
7+ $ paths [] = $ arg ;
8+ }
9+ }
10+ $ path = implode ( '/ ' , $ paths );
11+
12+ return preg_replace ( '#/+# ' , '/ ' , $ path );
13+ }
14+
15+ function wp_canonicalize_path ( $ path ) {
16+ // Convert to absolute path
17+ if ( ! str_starts_with ( $ path , '/ ' ) ) {
18+ $ path = '/ ' . $ path ;
19+ }
20+
21+ // Resolve . and ..
22+ $ parts = explode ( '/ ' , $ path );
23+ $ normalized = array ();
24+ foreach ( $ parts as $ part ) {
25+ if ( $ part === '. ' || $ part === '' ) {
26+ continue ;
27+ }
28+ if ( $ part === '.. ' ) {
29+ array_pop ( $ normalized );
30+ continue ;
31+ }
32+ $ normalized [] = $ part ;
33+ }
34+
35+ // Reconstruct path
36+ $ result = '/ ' . implode ( '/ ' , $ normalized );
37+ if ( $ result === '/. ' ) {
38+ $ result = '/ ' ;
39+ }
40+ return $ result === '' ? '/ ' : $ result ;
41+ }
You can’t perform that action at this time.
0 commit comments