From 9863871df4088ae9075a2905ecd1f6ffd7438e39 Mon Sep 17 00:00:00 2001 From: Jared Whiklo Date: Wed, 17 Jan 2024 09:53:33 -0600 Subject: [PATCH] More changes --- .gitignore | 1 + src/BagUtils.php | 4 ++-- tests/ManifestTest.php | 2 +- 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/.gitignore b/.gitignore index 2272fe4..b99cf2c 100644 --- a/.gitignore +++ b/.gitignore @@ -2,3 +2,4 @@ vendor/ clover.xml mytracedir/ +.phpunit.result.cache diff --git a/src/BagUtils.php b/src/BagUtils.php index bfd655d..b964f52 100644 --- a/src/BagUtils.php +++ b/src/BagUtils.php @@ -66,7 +66,7 @@ private function __construct() */ public static function baseInData(string $path): string { - if (substr($path, 0, 5) !== 'data/') { + if (!str_starts_with($path, 'data/')) { $path = "data/" . ltrim($path, "/"); } return $path; @@ -120,7 +120,7 @@ public static function getAbsolute(string $path, bool $add_absolute = false): st { $path = self::standardizePathSeparators($path); // Check if path start with a separator (UNIX) - $startWithSeparator = substr($path, 0, 1) === '/'; + $startWithSeparator = str_starts_with($path, '/'); // Check if start with drive letter preg_match('/^[a-z]:/i', $path, $matches); $startWithLetterDir = $matches[0] ?? false; diff --git a/tests/ManifestTest.php b/tests/ManifestTest.php index 9a81c9f..8a70408 100644 --- a/tests/ManifestTest.php +++ b/tests/ManifestTest.php @@ -331,7 +331,7 @@ public function testValidatePathOutsideBagCreate(): void { $bag = Bag::create($this->tmpdir); $this->expectException(BagItException::class); - $this->expectErrorMessage("Path data/../../pictures/another_picture.txt resolves outside the bag."); + $this->expectExceptionMessage("Path data/../../pictures/another_picture.txt resolves outside the bag."); $bag->addFile(self::TEST_IMAGE['filename'], "data/../../pictures/another_picture.txt"); } }