Welcome Guest, Not a member yet? Register   Sign In
Tilde(~) in Path Breaks CI4 (used in iCloud Drive Path)
#1

CI4 breaks when it encounters a path that has a tilde(~) in it.
Unfortunately, Apple uses tildes in its iCloud Drive path name, which is rendered as:
Code:
/Users/username/Library/Mobile Documents/com~apple~CloudDocs


When using PHP's built-in web server on MacOS:
Code:
cd  /Users/moo/Library/Mobile Documents/com~apple~CloudDocs/Sites/ci4b1/
php -S localhost:8892 -t $(pwd)/public
... the user-visible path
Code:
/Users/myname/Sites/ci4b1/
...ACTUALLY resolves to
Code:
/Users/myname/Library/Mobile Documents/com~apple~CloudDocs/Sites/ci4b1/
Returning this response:
Code:
Fatal error: Uncaught Error: Class 'Config\App' not found in /Users/myname/Library/Mobile Documents/com~apple~CloudDocs/Sites/ci4b1/vendor/codeigniter4/framework/system/Config/Config.php on line 139

The same fatal error returns when executing spark at the CLI if the CI4 folder is located in a path containing a tilde(~) .

Code:
➜  ci4b1 pwd
/Users/moo/Desktop/folder_with_a_tilde~/ci4b1
➜  ci4b1 ./spark
PHP Fatal error:  Uncaught Error: Class 'Config\App' not found in /Users/moo/Desktop/folder_with_a_tilde~/ci4b1/vendor/codeigniter4/framework/system/Config/Config.php:139
Stack trace:
#0 /Users/moo/Desktop/folder_with_a_tilde~/ci4b1/vendor/codeigniter4/framework/system/Config/Config.php(80): CodeIgniter\Config\Config::createClass('Config\\App')
#1 /Users/moo/Desktop/folder_with_a_tilde~/ci4b1/vendor/codeigniter4/framework/system/Common.php(99): CodeIgniter\Config\Config::get('Config\\App', true)
#2 /Users/moo/Desktop/folder_with_a_tilde~/ci4b1/vendor/codeigniter4/framework/system/bootstrap.php(158): config('Config\\App')
#3 /Users/moo/Desktop/folder_with_a_tilde~/ci4b1/spark(44): require('/Users/moo/Desk...')
#4 {main}
 thrown in /Users/moo/Desktop/folder_with_a_tilde~/ci4b1/vendor/codeigniter4/framework/system/Config/Config.php on line 139

Fatal error: Uncaught Error: Class 'Config\App' not found in /Users/moo/Desktop/folder_with_a_tilde~/ci4b1/vendor/codeigniter4/framework/system/Config/Config.php:139
Stack trace:
#0 /Users/moo/Desktop/folder_with_a_tilde~/ci4b1/vendor/codeigniter4/framework/system/Config/Config.php(80): CodeIgniter\Config\Config::createClass('Config\\App')
#1 /Users/moo/Desktop/folder_with_a_tilde~/ci4b1/vendor/codeigniter4/framework/system/Common.php(99): CodeIgniter\Config\Config::get('Config\\App', true)
#2 /Users/moo/Desktop/folder_with_a_tilde~/ci4b1/vendor/codeigniter4/framework/system/bootstrap.php(158): config('Config\\App')
#3 /Users/moo/Desktop/folder_with_a_tilde~/ci4b1/spark(44): require('/Users/moo/Desk...')
#4 {main}
 thrown in /Users/moo/Desktop/folder_with_a_tilde~/ci4b1/vendor/codeigniter4/framework/system/Config/Config.php on line 139
➜  ci4b1

(Using CodeIgniter since 1.x)
Reply
#2

Does anyone have an idea of how we can work around this?

The error occurs in the final line of
/Users/moo/Desktop/folder_with_a_tilde~/ci4b1/vendor/codeigniter4/framework/system/Config/Config.php
in createClass where we are creating a new class instance using the name that was passed in.

vendor/codeigniter4/framework/system/Config/Config::createClass(string $name):
Code:
    /**
     * Find configuration class and create instance
     *
     * @param string $name Classname
     *
     * @return mixed|null
     */
    private static function createClass(string $name)
    {

       if (class_exists($name))
        {
            return new $name();
        }

        $locator = Services::locator();

       $file    = $locator->locateFile($name, 'Config');

        if (empty($file))
        {
            return null;
        }

        $name = $locator->getClassname($file);

        if (empty($name))
        {
            return null;
        }
               CODE DIES HERE:
        return new $name();
    }

(Using CodeIgniter since 1.x)
Reply
#3

From what I have read it's a short cut for you home folder.
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )
Reply
#4

(03-05-2019, 04:27 AM)InsiteFX Wrote: From what I have read it's a short cut for you home folder.

Yes, it is the actual path to the mount points for MacOS iCloud Drive/ and iOS "Files" app.

Since that remote storage mechanism is so useful for developers using MacOS,
I'm trying to figure out how to get CodeIgniter 4 working there.

(Using CodeIgniter since 1.x)
Reply
#5

Anyone have an idea for a workaround?

(Using CodeIgniter since 1.x)
Reply
#6

If you can get the path to the short cut then you should be able to just enter that
as the url link.
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )
Reply
#7

(03-07-2019, 04:16 AM)InsiteFX Wrote: If you can get the path to the short cut then you should be able to just enter that
as the url link.

Read my post and you'll see that I've done that.

(Using CodeIgniter since 1.x)
Reply
#8

Can you use a route for this, so that the tilde is not in the URL?
Reply
#9

Well, the obvious answer is don't store it in the iCloud drive Smile

Here's a workaround to expand the filenames, though I'm not sure how many different places would need to use that. I'm also unconvinced it's a good thing to have in core as it feels like it could be a security issue, though I'd have to think for a bit on when it could be safe and when not.
Reply
#10

The issue is caused by the sanitizeFilename method on line 301 of the file vendor/codeigniter4/framework/system/Autoloader/Autoloader.php. The function transforms a path such as /com~apple~CloudDocs/sites, which is perfectly legitimate on a Mac, into /comappleCloudDocs/sites, rendering all paths invalid.

I solved the issue by changing line 307:

PHP Code:
$filename preg_replace('/[^0-9\p{L}\s\/\-\_\.\:\\\\]/u'''$filename); 
To
PHP Code:
$filename preg_replace('/[^0-9\p{L}\s\/\-\_\.\:\\\\~]/u'''$filename); 
I don't know if there is a better way to avoid making changes to system files, but with this modification, CI4 works from iCloud directory on Mac.
Reply




Theme © iAndrew 2016 - Forum software by © MyBB