Skip to content

Commit 13fc3f4

Browse files
committed
Fix path checking
1 parent c35743f commit 13fc3f4

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

src/Phug/Compiler/Locator/FileLocator.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ private function getFullPath($location, $path, $extension)
2121

2222
$length = strlen($extension);
2323

24-
if ($length && substr($path, $length) === $extension &&
24+
if ($length && substr($path, -$length) === $extension &&
2525
@is_file($fullPath = "$location/$path") && is_readable($fullPath)
2626
) {
2727
return realpath($fullPath);

tests/Phug/Compiler/Locator/FileLocatorTest.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,21 @@ public function testLocate()
2828
'/views/base.pug',
2929
str_replace('\\', '/', $locator->locate('base', $paths, $extensions))
3030
);
31+
self::assertFileExists($locator->locate('base.pug', $paths, $extensions));
3132
self::assertStringEndsWith(
3233
'/views/base.pug',
3334
str_replace('\\', '/', $locator->locate('base.pug', $paths, $extensions))
3435
);
36+
self::assertFileExists($locator->locate('first-module', $paths, $extensions));
37+
self::assertStringEndsWith(
38+
'/mixins/lib1/first-module.pug',
39+
str_replace('\\', '/', $locator->locate('first-module', $paths, $extensions))
40+
);
41+
self::assertFileExists($locator->locate('first-module.pug', $paths, $extensions));
42+
self::assertStringEndsWith(
43+
'/mixins/lib1/first-module.pug',
44+
str_replace('\\', '/', $locator->locate('first-module.pug', $paths, $extensions))
45+
);
3546

3647
self::assertFileExists($locator->locate('../layouts/base', $paths, $extensions));
3748
self::assertStringEndsWith(

0 commit comments

Comments
 (0)