-
Notifications
You must be signed in to change notification settings - Fork 1.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Bug: Inconsistent behavior of view renderer on Windows and Linux #3529
Comments
On your preferred solution, please be aware that the separator for Windows is also backslashes. So checking for a "namespaced string" on Windows will give a false positive. Since the Opinions? @michalsn @MGatner @lonnieezell @samsonasik |
I think you're right about the false positives. However, I feel requiring a file extension for a view to be loaded via the 'path'-way might be a BC breaking change, as then, loading views via
So if a filename does not contain backslashes, it is handled as a folder/file path. If it does contain backslashes, als forward slashes are replaced by backslashes and namespaces are checked.
This way any view with a file extension will be handled as a path (as far as I understand, namespaced files cannot have extensions, right?) and also views that only contain forward slashes. |
Spot on for the BC break. I did not think of that. The legacyLocate method is already deprecated so reliance on that must be removed. I was also thinking somewhat the same on your conditional check. That may somehow solve this. |
Ah alright, I didn't see that legacyLocate is deprecated. This would require the above change in the |
To be honest I don't really see an issue here. Paths with Mistakes... well, maybe they will happen - I can't argue with this. But the user guide clearly states how files in folders should be loaded and how from namespaces. If people will follow the user guide they're safe. |
Actually can't really argue against that. The initial idea was to have CI consistently throw the same exceptions on both OS when people mess with the intended view loading options. If you guys think this can stay the way it is, I'm happy with closing, too :) |
Closing as behavior seems to be desired. |
Direction
The view renderer behaves differently on Windows and Linux in specific cases, which should be fixed for consistency.
Corresponding forum thread: https://forum.codeigniter.com/thread-77305.html
Describe the bug
If a view file is called incorrectly by using namespace syntax (i.e. backslashes) when folder syntax (i.e. forward slashes) should be used, the view will still be loaded in Windows environments, but will fail on Linus systems (expected behaviour).
CodeIgniter 4 version
4.0.4 (latest develop)
Affected module(s)
View renderer
Expected behavior, and steps to reproduce if appropriate
view('Auth\login')
.This can lead to problems, when, e.g., a view is successfully loaded in a Windows development environment, but subsequently fails to load in the Linux production environment.
Background
Looking inside the
render()
function of theView
class reveals the following behaviour:Windows:
$view: Auth\login
$renderVars['file']: C:\XAMPP\htdocs\ci-ttv\app\Config/../Views/Auth\login.php
is_file: bool(true)
Debian:
$view: Auth\login
$renderVars['file']: /var/www/xxx/html/intern/app/Config/../Views/Auth\login.php
is_file: bool(false) (hence, FileLocator is called)
On Debian, the FileLocator subsequently cannot find the view file, as is (rightly) assumes the string to be namespaced, but cannot locate the namespace location.
Suggested solution
view()
method, it should be captured and treated as a namespaced string (similar to how the FileLocator handles it). In this case, theis_file
check and other stuff in theView->render()
function can be skipped and the parameter can directly be passed to the FileLocator.$view
viais_file
all backslashed should be replaced with forward slashed temporarily (this is also somewhat present in the fileloader).Personally, I prefer the first solution as I feel that the second option promotes wrong coding and also the first option seems to be more consistent with the way FileLocator works.
Context
The text was updated successfully, but these errors were encountered: