aaronlord / laroute

Generate Laravel route URLs from JavaScript.
MIT License
794 stars 139 forks source link

invalid unicode escape sequence #89

Open ghost opened 5 years ago

ghost commented 5 years ago

After generating the file and viewing the page I have spotted an error. An error is to do with an invalid Unicode escape sequence. After searching for the bug in the laroute.js file I spotted that JS was trying to scape "\u" in the action part of the route statement.

Whilst I have hardcoded the fix for myself - it might be of benefit to adjust getRouteInformation() method to handle any backslashes within an action.

    /**
     * Get the route information for a given route.
     *
     * @param $route \Illuminate\Routing\Route
     * @param $filter string
     * @param $namespace string
     *
     * @return array
     */
    protected function getRouteInformation(Route $route, $filter, $namespace)
    {
        $host    = $route->domain();
        $methods = $route->methods();
        $uri     = $route->uri();
        $name    = $route->getName();
        $action  = $route->getActionName();
        $laroute = array_get($route->getAction(), 'laroute', null);

        if(!empty($namespace)) {
            $a = $route->getAction();

            if(isset($a['controller'])) {
                $action = str_replace($namespace.'\\', '', $action);
            }
        }

    // escape backslashes
        $action = addslashes($action); 

        switch ($filter) {
            case 'all':
                if($laroute === false) return null;
                break;
            case 'only':
                if($laroute !== true) return null;
                break;
        }

        return compact('host', 'methods', 'uri', 'name', 'action');
    }