Skip to content

Commit 30712bb

Browse files
Fixed handling of empty source map entries (#316)
Source maps may contain empty map entries / empty file paths. Fixes: failing gazelle tests (e.g., see and test `npm pack morphi`)
1 parent 0b22b2f commit 30712bb

File tree

2 files changed

+7
-5
lines changed

2 files changed

+7
-5
lines changed

project/plugins.sbt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,4 @@ addSbtPlugin("com.github.sbt" % "sbt-native-packager" % "1.9.16")
22
addSbtPlugin("org.scalameta" % "sbt-scalafmt" % "2.5.0")
33
addSbtPlugin("io.shiftleft" % "sbt-ci-release-early" % "2.0.27")
44
addSbtPlugin("com.dwijnand" % "sbt-dynver" % "4.1.1")
5-
addSbtPlugin("com.eed3si9n" % "sbt-assembly" % "1.1.0")
65
addSbtPlugin("com.eed3si9n" % "sbt-buildinfo" % "0.10.0")

src/main/scala/io/shiftleft/js2cpg/parser/JsSource.scala

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -82,20 +82,22 @@ class JsSource(val srcDir: File, val projectDir: Path, val source: Source) {
8282
}
8383
}
8484

85-
private def constructSourceFilePath(sourceFileName: String): File = sourceFileName match {
86-
case _ if absoluteFilePath.contains(NuxtTranspiler.NUXT_FOLDER) && srcDir.path.compareTo(projectDir) == 0 =>
85+
private def constructSourceFilePath(sourceFileName: String): File = {
86+
if (sourceFileName.isEmpty) {
87+
srcDir / source.getName
88+
} else if (absoluteFilePath.contains(NuxtTranspiler.NUXT_FOLDER) && srcDir.path.compareTo(projectDir) == 0) {
8789
// For nuxt-js transpilation we have the same src and project dir and we need some special handling here
8890
if (sourceFileName.startsWith(WEBPACK_PREFIX)) {
8991
val replacedName = FileUtils.cleanPath(sourceFileName.replace(WEBPACK_PREFIX, ""))
9092
srcDir / replacedName.substring(replacedName.indexOf("/") + 1)
9193
} else {
9294
File(absoluteFilePath).parent / sourceFileName
9395
}
94-
case _ if sourceFileName.startsWith(WEBPACK_PREFIX) =>
96+
} else if (sourceFileName.startsWith(WEBPACK_PREFIX)) {
9597
// Additionally, source map files coming from webpack (e.g., from Vue transpilation) are somewhat hidden
9698
val replacedName = sourceFileName.replace(WEBPACK_PREFIX, "")
9799
srcDir / replacedName.substring(replacedName.indexOf("/") + 1)
98-
case _ =>
100+
} else {
99101
val cleanedPath = FileUtils.cleanPath(sourceFileName)
100102
// having "/" here is fine as JS source maps always have platform independent path separators
101103
val lookupPath = if (cleanedPath.contains("/" + srcDir.name + "/")) {
@@ -115,6 +117,7 @@ class JsSource(val srcDir: File, val projectDir: Path, val source: Source) {
115117
}
116118
}
117119
srcFilePath
120+
}
118121
}
119122

120123
private def sourceMapOrigin(): Option[SourceMapOrigin] = {

0 commit comments

Comments
 (0)