From 17a3c7a41e42b2120f259e20d999e31c30fdb289 Mon Sep 17 00:00:00 2001 From: David Baker Effendi Date: Mon, 6 Nov 2023 14:35:51 +0200 Subject: [PATCH] [pysrc2cpg] Handle Import Resolution when Root is File (#3795) This fixes a bug where `root` is always assumed to be a directory in `ImportResolverPass`. --- .../main/scala/io/joern/pysrc2cpg/ImportResolverPass.scala | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/joern-cli/frontends/pysrc2cpg/src/main/scala/io/joern/pysrc2cpg/ImportResolverPass.scala b/joern-cli/frontends/pysrc2cpg/src/main/scala/io/joern/pysrc2cpg/ImportResolverPass.scala index fed0e0035789..355b7f151e4f 100644 --- a/joern-cli/frontends/pysrc2cpg/src/main/scala/io/joern/pysrc2cpg/ImportResolverPass.scala +++ b/joern-cli/frontends/pysrc2cpg/src/main/scala/io/joern/pysrc2cpg/ImportResolverPass.scala @@ -12,7 +12,9 @@ import java.util.regex.{Matcher, Pattern} class ImportResolverPass(cpg: Cpg) extends XImportResolverPass(cpg) { - private lazy val root = cpg.metaData.root.headOption.getOrElse("").stripSuffix(JFile.separator) + private lazy val root = BFile(cpg.metaData.root.headOption.getOrElse("").stripSuffix(JFile.separator)) match + case f if f.isDirectory => f.pathAsString + case f => f.parent.pathAsString override protected def optionalResolveImport( fileName: String,