From 45c8173029108c231798217aa23c391ca265625c Mon Sep 17 00:00:00 2001 From: Dave Mc Nicoll Date: Tue, 19 Oct 2021 12:39:14 +0000 Subject: [PATCH] - Mostly bugfixes made while working on ParcInfo --- src/Compiler.php | 6 +++--- src/Extension/JsonExtension.php | 2 +- src/Extension/UrlExtension.php | 18 ++++++++++++++---- src/FileFetcher.php | 10 ++++++++++ 4 files changed, 28 insertions(+), 8 deletions(-) diff --git a/src/Compiler.php b/src/Compiler.php index 3779495..640c672 100644 --- a/src/Compiler.php +++ b/src/Compiler.php @@ -48,7 +48,7 @@ class Compiler list($token, $arguments) = array_pad(array_filter(explode(' ', $matches[2], 2), 'strlen'), 2, null); - $token = trim($token); + $token = strtolower(trim($token)); # @TODO Refractor this parts to allows registration to the tag's name if ( $this->tagList[$token] ?? false ) { @@ -87,7 +87,7 @@ class Compiler public function registerControlStructure(ControlStructure\ControlStructure $controlStructureObject) : self { foreach($controlStructureObject->tokens ?? (array) ( $controlStructureObject->token ?? [] ) as $token) { - $this->tagList[$token] = $controlStructureObject; + $this->tagList[strtolower($token)] = $controlStructureObject; } return $this; @@ -98,7 +98,7 @@ class Compiler $tokens = $extension->tokens ?? (array) ( $extension->token ?? [] ); foreach($tokens as $token) { - $this->extensionList[$token] = $extension; + $this->extensionList[strtolower($token)] = $extension; } if (! $tokens ) { diff --git a/src/Extension/JsonExtension.php b/src/Extension/JsonExtension.php index ad8fd21..32e447d 100644 --- a/src/Extension/JsonExtension.php +++ b/src/Extension/JsonExtension.php @@ -8,7 +8,7 @@ class JsonExtension implements Extension, FunctionExtension { public array $token = [ "json", "json.pretty" ]; - public int $flags = JSON_HEX_TAG | \JSON_HEX_APOS | \JSON_HEX_QUOT | \JSON_THROW_ON_ERROR; + public int $flags = JSON_HEX_TAG | \JSON_HEX_QUOT | \JSON_THROW_ON_ERROR | \JSON_UNESCAPED_UNICODE; public function parse(/*\Picae\Compiler\Context*/ &$context, ?string $arguments, string $token) { diff --git a/src/Extension/UrlExtension.php b/src/Extension/UrlExtension.php index ca50132..99a66df 100644 --- a/src/Extension/UrlExtension.php +++ b/src/Extension/UrlExtension.php @@ -165,7 +165,7 @@ class UrlExtension implements Extension { $_SERVER['X-Forwarded-Ssl'] ?? "", $_SERVER['X-Forwarded-Proto'] ?? "", $_SERVER['X-Forwarded-Protocol'] ?? "", - ])); + ])) || isset($_SERVER['HTTP_X_ARR_SSL']); return $header || ( "443" === ( $_SERVER['SERVER_PORT'] ?? "" ) ) @@ -183,7 +183,7 @@ class UrlExtension implements Extension { list($variable, $default) = explode('=', $item[1]); } elseif (strpos($item[1], ":") !== false) { - list($variable, ) = explode(':', $item[1]); + list($variable, $type) = explode(':', $item[1]); } else { $variable = $item[1]; @@ -191,6 +191,7 @@ class UrlExtension implements Extension { if ( array_key_exists($variable, $arguments) ) { $value = $arguments[ $variable ]; + unset($arguments[ $variable ]); } else { @@ -198,13 +199,22 @@ class UrlExtension implements Extension { } $search[ $item[0] ] = $value; - } $route = str_replace(array_keys($search), array_values($search), $route); } - return $route; + /* + * @TODO - must also take into account that recursivity is possible here [/test[/another[/still]]], + * so the regex must be adjusted (or simply using another method could also be a possiblity) + * while(strpos($route, '[') !== false && strpos($route, ']') !== false ) { + if ( preg_match_all('~[(.*?)]~si', $route, $matches, PREG_SET_ORDER) ) { + } + }*/ + $route = trim(str_replace([ '[', ']' ], '', $route), '/'); + + return $route; } + } diff --git a/src/FileFetcher.php b/src/FileFetcher.php index 0921a61..ec4b760 100644 --- a/src/FileFetcher.php +++ b/src/FileFetcher.php @@ -43,8 +43,13 @@ class FileFetcher foreach($this->folderList as $folder) { foreach($this->supportedExtensionList as $extension) { $file = $folder['path'] . DIRECTORY_SEPARATOR . "$fileName.$extension"; + $file = str_replace([ '\\', '/' ], DIRECTORY_SEPARATOR, $file); if ( file_exists($file) ) { + if ( is_dir($file) ) { + throw new \RuntimeException("Given view file `$fileName` is a folder, you must provide a valid filename."); + } + return $file; } } @@ -53,8 +58,13 @@ class FileFetcher # Fallback on full-path foreach($this->folderList as $folder) { $file = $folder['path'] . DIRECTORY_SEPARATOR . $fileName; + $file = str_replace([ '\\', '/' ], DIRECTORY_SEPARATOR, $file); if ( file_exists($file) ) { + if ( is_dir($file) ) { + throw new \RuntimeException("Given view file `$fileName` is a folder, you must provide a valid filename."); + } + return $file; } }