@@ -71,6 +71,12 @@ void makeParentPathInplace(std::vector<std::string_view> &parts) {
7171 }
7272}
7373
74+ std::vector<std::string_view> makeParentPath (const std::string_view &path) {
75+ auto parts = explodePath (path);
76+ makeParentPathInplace (parts);
77+ return parts;
78+ }
79+
7480std::vector<std::string_view> simplifyPath (const std::vector<std::string_view> &parts) {
7581 std::vector<std::string_view> result;
7682 if (!parts.empty ()) {
@@ -89,17 +95,18 @@ std::vector<std::string_view> simplifyPath(const std::vector<std::string_view> &
8995 return result;
9096}
9197
92- std::string joinPath (const std::string_view &baseDir, const std::string_view &rest) {
93- auto pathComponents = simplifyPath (explodePath (baseDir));
94- auto restComponents = simplifyPath (explodePath (rest));
98+ std::vector<std::string_view> joinPath (const std::vector<std::string_view> &baseDir,
99+ const std::vector<std::string_view> &rest) {
100+ auto pathComponents = simplifyPath (baseDir);
101+ auto restComponents = simplifyPath (rest);
95102 for (auto &&part : restComponents) {
96103 if (" .." == part) {
97104 makeParentPathInplace (pathComponents);
98105 } else if (!part.empty () && " ." != part) {
99106 pathComponents.emplace_back (part);
100107 }
101108 }
102- return implodePath ( pathComponents) ;
109+ return pathComponents;
103110}
104111
105112std::pair<std::string_view, std::string_view>
@@ -192,7 +199,9 @@ CxxNodeApiHostModule::resolveRelativePath(facebook::jsi::Runtime &rt,
192199 const std::string_view &requiredPackageName,
193200 const std::string_view &requiredFrom) {
194201 // "Rebase" the relative path to get a proper package-relative path
195- const std::string mergedSubpath = joinPath (requiredFrom, requiredPath);
202+ const auto requiredFromDirParts = makeParentPath (requiredFrom);
203+ const auto requiredPathParts = explodePath (requiredPath);
204+ const std::string mergedSubpath = implodePath (joinPath (requiredFromDirParts, requiredPathParts));
196205 if (!isModulePathLike (mergedSubpath)) {
197206 throw jsi::JSError (rt, " Computed subpath is invalid. Check `requiredPath` and `requiredFrom`." );
198207 }
0 commit comments