Skip to content

Commit

Permalink
[ruby] Include y(a)ml, xml, and erb files (#4846)
Browse files Browse the repository at this point in the history
  • Loading branch information
DavidBakerEffendi authored Aug 13, 2024
1 parent cd45eea commit 00c911f
Show file tree
Hide file tree
Showing 2 changed files with 72 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,16 @@ class ConfigFileCreationPass(cpg: Cpg) extends XConfigFileCreationPass(cpg) {
case None => Seq()
}

override protected val configFileFilters: List[File => Boolean] = List(validGemfilePaths.contains)
override protected val configFileFilters: List[File => Boolean] = List(
// Gemfiles
validGemfilePaths.contains,
extensionFilter(".ini"),
// YAML files
extensionFilter(".yaml"),
extensionFilter(".yml"),
// XML files
extensionFilter(".xml"),
// ERB files
extensionFilter(".erb")
)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
package io.joern.rubysrc2cpg.passes

import io.joern.rubysrc2cpg.testfixtures.RubyCode2CpgFixture
import io.shiftleft.semanticcpg.language.*

class ConfigFileCreationPassTests extends RubyCode2CpgFixture {

"yaml files should be included" in {
val cpg = code(
"""
|foo:
| bar
|""".stripMargin,
"config.yaml"
)

val config = cpg.configFile.name("config.yaml").head
config.content should include("foo:")
}

"yml files should be included" in {
val cpg = code(
"""
|foo:
| bar
|""".stripMargin,
"config.yml"
)

val config = cpg.configFile.name("config.yml").head
config.content should include("foo:")
}

"xml files should be included" in {
val cpg = code(
"""
|<foo>
| <p>bar<p>
|</foo>
|""".stripMargin,
"config.xml"
)

val config = cpg.configFile.name("config.xml").head
config.content should include("<p>bar<p>")
}

"erb files should be included" in {
val cpg = code(
"""
|<%= 1 + 2 %>
|""".stripMargin,
"foo.erb"
)

val config = cpg.configFile.name("foo.erb").head
config.content should include("1 + 2")
}

}

0 comments on commit 00c911f

Please sign in to comment.