Skip to content
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

Merged
merged 1 commit into from Jan 25, 2018

Conversation

darensipes
Copy link
Contributor

@darensipes darensipes commented Jan 10, 2018

…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 say xlsx both have a strlen of 4, strrpos returns false and 4-4 = 0 therefore false == 0 is true which is incorrect.

@codecov-io
Copy link

codecov-io commented Jan 10, 2018

Codecov Report

Merging #11620 into master will not change coverage.
The diff coverage is 100%.

Impacted file tree graph

@@            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
Impacted Files Coverage Δ Complexity Δ
src/View/View.php 92.25% <100%> (ø) 155 <0> (+1) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update a02ac7b...4c3638f. Read the comment docs.

@markstory markstory added this to the 3.5.10 milestone Jan 10, 2018
Copy link
Member

@markstory markstory left a 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) {
Copy link
Member

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.

Copy link
Member

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 ?

Copy link
Member

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.

Copy link
Contributor Author

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?

Copy link
Member

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.

@markstory markstory modified the milestones: 3.5.10, 3.5.11, 3.5.12 Jan 15, 2018
@markstory markstory self-assigned this Jan 24, 2018
@markstory markstory merged commit 4c3638f into cakephp:master Jan 25, 2018
markstory added a commit that referenced this pull request Jan 25, 2018
Ensure that controller names with length equal to the view subDir still
have the subdirectory applied.
@darensipes darensipes deleted the view-subdir-issue branch May 14, 2018 14:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants