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
Fixing issue with how the check is done for determining if templatePa… #11620
Fixing issue with how the check is done for determining if templatePa… #11620
Conversation
…th already terminates with subDir
Codecov Report
@@ Coverage Diff @@
## master #11620 +/- ##
=========================================
Coverage 93.36% 93.36%
- Complexity 13014 13015 +1
=========================================
Files 436 436
Lines 32831 32831
=========================================
Hits 30652 30652
Misses 2179 2179
Continue to review full report at Codecov.
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we could get a test for this case that would be great. If you need a hand let me know and I can work on a test.
@@ -1249,7 +1249,7 @@ protected function _getViewFileName($name = null) | |||
if (strlen($this->subDir)) { | |||
$subDir = $this->subDir . DIRECTORY_SEPARATOR; | |||
// Check if templatePath already terminates with subDir | |||
if (strrpos($templatePath, $subDir) == strlen($templatePath) - strlen($subDir)) { | |||
if ($templatePath != $subDir && substr($templatePath, -(strlen($subDir))) == $subDir) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can use strict !==
and ===
when you are comparing strings now.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't $templatePath
and $subDir
be equal sometimes ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When would that happen? Extension directories are generally lower case, like csv
while template paths usually end with the controller name Csvs
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@dereuromark - yes, maybe ===
should be used.
@saeideng - I agree with mark that is shouldn't happen because $templatePath
is using the controller name and the first letter is uppercase, whereas the $subDir
is typically all lowercase.
@markstory - Wouldn't the test you added during this commit (115a354) cover this case as well?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It does to some extent. But you have a new scenario that requires different code. With only the existing test, this change could be reverted and there wouldn't be a failing test to let us know there was a regression.
Ensure that controller names with length equal to the view subDir still have the subdirectory applied.
…th already terminates with subDir
The problem the with current check:
strrpos($templatePath, $subDir) == strlen($templatePath) - strlen($subDir)
Lets say your have a templatePath that is equal to
Jobs
for example and you have a subDir equal to sayxlsx
both have astrlen
of4
,strrpos
returns false and 4-4 = 0 thereforefalse == 0
istrue
which is incorrect.