From 80eac6b67402af547938136bd32befcab588ce17 Mon Sep 17 00:00:00 2001 From: Christian Banse Date: Fri, 28 Feb 2025 23:01:27 +0100 Subject: [PATCH] Added canonicalFile --- .../aisec/cpg/frontends/python/PythonLanguageFrontend.kt | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/cpg-language-python/src/main/kotlin/de/fraunhofer/aisec/cpg/frontends/python/PythonLanguageFrontend.kt b/cpg-language-python/src/main/kotlin/de/fraunhofer/aisec/cpg/frontends/python/PythonLanguageFrontend.kt index 37a453c8648..945da30301b 100644 --- a/cpg-language-python/src/main/kotlin/de/fraunhofer/aisec/cpg/frontends/python/PythonLanguageFrontend.kt +++ b/cpg-language-python/src/main/kotlin/de/fraunhofer/aisec/cpg/frontends/python/PythonLanguageFrontend.kt @@ -314,8 +314,10 @@ class PythonLanguageFrontend(language: Language, ctx: Tr // We need to resolve the path relative to the top level to get the full module identifier // with packages. Note: in reality, only directories that have __init__.py file present are - // actually packages, but we skip this for now - var relative = path.relativeToOrNull(topLevel.toPath()) + // actually packages, but we skip this for now. Since we are dealing with potentially + // relative paths, we need to canonicalize both paths. + var relative = + path.toFile().canonicalFile.relativeToOrNull(topLevel.canonicalFile)?.toPath() var module = path.nameWithoutExtension var modulePaths = (relative?.parent?.pathString?.split("/") ?: listOf()) + module