diff --git a/joern-cli/frontends/pysrc2cpg/pythonGrammar.jj b/joern-cli/frontends/pysrc2cpg/pythonGrammar.jj index 37b748432235..862d9c8bc6d7 100644 --- a/joern-cli/frontends/pysrc2cpg/pythonGrammar.jj +++ b/joern-cli/frontends/pysrc2cpg/pythonGrammar.jj @@ -822,7 +822,13 @@ SPECIAL_TOKEN: { SKIP: { { currentIndent += 1; } -| { currentIndent = currentIndent / 8 + 8; } +| { + // The "/ 8 * 8" rounds down to the closest multiple of 8. + // This is needed to handle python 2 mixed space and tab use cases + // where tab is not strictly counted as 8 spaces but rather adds the + // amount of spaces to get to the next multiple of 8. + currentIndent = currentIndent / 8 * 8 + 8; +} | { currentIndent = 0; } | | { diff --git a/joern-cli/frontends/pysrc2cpg/src/test/scala/io/joern/pythonparser/ParserTests.scala b/joern-cli/frontends/pysrc2cpg/src/test/scala/io/joern/pythonparser/ParserTests.scala index 0a27fab542a4..9ac869bbbc5e 100644 --- a/joern-cli/frontends/pysrc2cpg/src/test/scala/io/joern/pythonparser/ParserTests.scala +++ b/joern-cli/frontends/pysrc2cpg/src/test/scala/io/joern/pythonparser/ParserTests.scala @@ -350,6 +350,7 @@ class ParserTests extends AnyFreeSpec with Matchers { | z = (x,y) |a""".stripMargin ) + testT("def init():\n\tmatch x:\n\t\tcase 'C':\n\t\t\tz = 1") } "explicit line joining tests" in {