Skip to content

Commit

Permalink
[pysrc2cpg] Handle Import Resolution when Root is File (#3795)
Browse files Browse the repository at this point in the history
This fixes a bug where `root` is always assumed to be a directory in `ImportResolverPass`.
  • Loading branch information
DavidBakerEffendi authored Nov 6, 2023
1 parent 824716d commit 17a3c7a
Showing 1 changed file with 3 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit 17a3c7a

Please sign in to comment.