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) {
689
689
return null ;
690
690
}
691
691
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
+
692
705
/**
693
706
* Installs dependencies for use by the TypeScript type checker.
694
707
* <p>
@@ -727,6 +740,9 @@ protected DependencyInstallationResult installDependencies(Set<Path> filesToExtr
727
740
if (!(json instanceof JsonObject )) continue ;
728
741
JsonObject jsonObject = (JsonObject ) json ;
729
742
file = file .toAbsolutePath ();
743
+ if (tryRelativize (sourceRoot , file ) == null ) {
744
+ continue ; // Ignore package.json files outside the source root.
745
+ }
730
746
packageJsonFiles .put (file , jsonObject );
731
747
732
748
String name = getChildAsString (jsonObject , "name" );
You can’t perform that action at this time.
0 commit comments