File tree Expand file tree Collapse file tree 1 file changed +16
-0
lines changed
Expand file tree Collapse file tree 1 file changed +16
-0
lines changed Original file line number Diff line number Diff line change @@ -689,6 +689,19 @@ private String getChildAsString(JsonObject obj, String name) {
689689 return null ;
690690 }
691691
692+ /**
693+ * Gets a relative path from <code>from</code> to <code>to</code> provided
694+ * the latter is contained in the former. Otherwise returns <code>null</code>.
695+ * @return a path or null
696+ */
697+ public static Path tryRelativize (Path from , Path to ) {
698+ Path relative = from .relativize (to );
699+ if (relative .startsWith (".." ) || relative .isAbsolute ()) {
700+ return null ;
701+ }
702+ return relative ;
703+ }
704+
692705 /**
693706 * Installs dependencies for use by the TypeScript type checker.
694707 * <p>
@@ -727,6 +740,9 @@ protected DependencyInstallationResult installDependencies(Set<Path> filesToExtr
727740 if (!(json instanceof JsonObject )) continue ;
728741 JsonObject jsonObject = (JsonObject ) json ;
729742 file = file .toAbsolutePath ();
743+ if (tryRelativize (sourceRoot , file ) == null ) {
744+ continue ; // Ignore package.json files outside the source root.
745+ }
730746 packageJsonFiles .put (file , jsonObject );
731747
732748 String name = getChildAsString (jsonObject , "name" );
You can’t perform that action at this time.
0 commit comments