Skip to content

Commit

Permalink
Merge pull request #14 from DanielSiepmann/bugfix/is_link-detection
Browse files Browse the repository at this point in the history
Respect symlinks in url_stat
  • Loading branch information
maks-rafalko authored Aug 7, 2020
2 parents 159ae3d + 89fd3e8 commit e3cf931
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 2 deletions.
12 changes: 10 additions & 2 deletions src/IncludeInterceptor.php
Original file line number Diff line number Diff line change
Expand Up @@ -377,12 +377,20 @@ public function unlink($path)
return $return;
}

public function url_stat($path)
public function url_stat($path, $flags)
{
self::disable();

try {
return is_readable($path) ? stat($path) : false;
if (is_readable($path) === false) {
return false;
}

if ($flags & STREAM_URL_STAT_LINK) {
return lstat($path);
}

return stat($path);
} finally {
self::enable();
}
Expand Down
15 changes: 15 additions & 0 deletions tests/IncludeInterceptorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -418,4 +418,19 @@ public function test_it_re_enables_interceptor_after_file_not_found_with_url_sta

$this->fail('Badly set up test, exception was not thrown');
}

public function test_it_respects_symlinks_in_url_stat(): void
{
$expected = include self::$files[2];

IncludeInterceptor::intercept(self::$files[1], self::$files[2]);
IncludeInterceptor::enable();

$symlink = sys_get_temp_dir() . '/symlink-intercept';
self::$files[] = $symlink;

symlink(self::$files[2], $symlink);

$this->assertTrue(is_link($symlink));
}
}

0 comments on commit e3cf931

Please sign in to comment.