From 401212da771af21eb25bd542344294330272f8e1 Mon Sep 17 00:00:00 2001 From: DevmateUtgenCppGeneralFBOrg Bot Date: Mon, 7 Sep 2026 06:05:55 -0700 Subject: [PATCH] xplat/js/react-native-github/packages/react-native/ReactCxxPlatform/react/io/platform/android/ResourceLoader.cpp Reviewed By: andrewdacenko Differential Revision: D119049814 --- .../io/tests/fbcode/ResourceLoaderTest.cpp | 38 +++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 packages/react-native/ReactCxxPlatform/react/io/tests/fbcode/ResourceLoaderTest.cpp diff --git a/packages/react-native/ReactCxxPlatform/react/io/tests/fbcode/ResourceLoaderTest.cpp b/packages/react-native/ReactCxxPlatform/react/io/tests/fbcode/ResourceLoaderTest.cpp new file mode 100644 index 00000000000..e68510a728f --- /dev/null +++ b/packages/react-native/ReactCxxPlatform/react/io/tests/fbcode/ResourceLoaderTest.cpp @@ -0,0 +1,38 @@ +/* + * Copyright (c) Meta Platforms, Inc. and affiliates. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + */ + +#include +#include + +namespace facebook::react { + +// Exercises the path-classification contract that ResourceLoader::isDirectory +// and isFile rely on for their "absolute path" fast path. This is pure lexical +// logic and performs no filesystem, JNI, or asset-manager access. +class ResourceLoaderTest : public ::testing::Test {}; + +TEST_F(ResourceLoaderTest, testIsAbsolutePathRejectsRelativePaths) { + // Relative paths must never take the absolute fast path, regardless of the + // separator or leading "./" or "../" components. + EXPECT_FALSE(ResourceLoader::isAbsolutePath("assets/index.bundle")); + EXPECT_FALSE(ResourceLoader::isAbsolutePath("./config.json")); + EXPECT_FALSE(ResourceLoader::isAbsolutePath("../parent/file.txt")); + EXPECT_FALSE(ResourceLoader::isAbsolutePath("bundle.js")); +} + +TEST_F(ResourceLoaderTest, testIsAbsolutePathRejectsEmptyPath) { + // An empty path has no root and must never be treated as absolute; otherwise + // isDirectory/isFile would take the absolute fast path for an invalid input. + EXPECT_FALSE(ResourceLoader::isAbsolutePath("")); +} + +TEST_F(ResourceLoaderTest, testIsAbsolutePathAcceptsAbsolutePaths) { + EXPECT_TRUE(ResourceLoader::isAbsolutePath("/data/data/com.app/bundle.js")); + EXPECT_TRUE(ResourceLoader::isAbsolutePath("/")); +} + +} // namespace facebook::react