Skip to content

Commit

Permalink
Use IOUtils to read file instead
Browse files Browse the repository at this point in the history
  • Loading branch information
johannescoetzee committed Jan 13, 2025
1 parent b2a3ecb commit 1b08f8c
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import io.joern.x2cpg.{Ast, AstCreatorBase, AstNodeBuilder, Defines, ValidationM
import io.shiftleft.codepropertygraph.generated.*
import io.shiftleft.codepropertygraph.generated.nodes.*
import io.shiftleft.semanticcpg.language.types.structure.NamespaceTraversal
import io.shiftleft.utils.IOUtils
import org.slf4j.LoggerFactory

import java.nio.charset.StandardCharsets
Expand Down Expand Up @@ -44,19 +45,7 @@ class AstCreator(relativeFileName: String, fileName: String, phpAst: PhpFile, di

override def createAst(): DiffGraphBuilder = {
if (!disableFileContent) {
fileContent = Some(Files.readString(Path.of(fileName)))

fileContent = fileEncodings.iterator
.map { encoding =>
Try(Files.readString(Path.of(fileName), encoding))
}
.collectFirst { case Success(content) =>
content
}

if (fileContent.isEmpty) {
logger.warn(s"Could not parse file using any standard charsets. File content will be missing for $fileName")
}
fileContent = Option(IOUtils.readEntireFile(Path.of(fileName)))
}

val ast = astForPhpFile(phpAst)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ class MethodTests extends PhpCode2CpgFixture {
fooMethod.file.head.content.substring(offsetStart, offsetEnd) shouldBe
"""function foo() {
| // ⦝
| $x = "🙂⨌🙂𐇐🙂🙂🙂🙂";
| $x = "??⨌????????????";
|}""".stripMargin
}
}
Expand Down

0 comments on commit 1b08f8c

Please sign in to comment.