Skip to content

Commit e6434b6

Browse files
author
Tebogo Selahle
committed
fix: recognise joern_inner_buffer appends as erb calls
1 parent 35b82a7 commit e6434b6

File tree

2 files changed

+8
-7
lines changed

2 files changed

+8
-7
lines changed

joern-cli/frontends/rubysrc2cpg/src/main/scala/io/joern/rubysrc2cpg/astcreation/AstForExpressionsCreator.scala

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -185,9 +185,7 @@ trait AstForExpressionsCreator(implicit withSchemaValidation: ValidationMode) {
185185
protected def astForMemberCall(node: RubyCallWithBase, isStatic: Boolean = false): Ast = {
186186

187187
def createMemberCall(n: RubyCallWithBase): Ast = {
188-
val isErbCall = n.methodName == Constants.joernErbBufferAppend && n.arguments.headOption.exists(
189-
_.span.text == "self.joern__buffer"
190-
)
188+
val isErbCall = n.methodName == Constants.joernErbBufferAppend
191189

192190
val (nodeOp, hasStringArguments, receiverAst) = if (isErbCall) {
193191
val hasStringArgs = n.arguments.tail.exists {
@@ -325,7 +323,11 @@ trait AstForExpressionsCreator(implicit withSchemaValidation: ValidationMode) {
325323
scope.tryResolveTypeReference(x.typeName).map(_.name).getOrElse(Defines.Any)
326324
}
327325
.orElse(Option(Defines.Any))
328-
val typeFullName = if node.memberName == "joern__buffer" then Constants.stringPrefix else Defines.Any
326+
val typeFullName = if (node.memberName == "joern__buffer" || node.memberName == "joern__inner_buffer") {
327+
Constants.stringPrefix
328+
} else {
329+
Defines.Any
330+
}
329331
val fieldAccess = callNode(
330332
node,
331333
code,

joern-cli/frontends/rubysrc2cpg/src/test/scala/io/joern/rubysrc2cpg/querying/ErbTests.scala

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -261,9 +261,8 @@ class ErbTests extends RubyCode2CpgFixture {
261261
inside(lambdaMethod.body.astChildren.l) {
262262
case _ :: _ :: (appendCallTemplate: Call) :: _ :: _ :: Nil =>
263263
appendCallTemplate.code shouldBe "self.joern__buffer_append(joern__inner_buffer, <%= form.text_field :name %>)"
264-
val List(selfId, appendCallArgOne, appendCallArgTwo: Call) = appendCallTemplate.argument.l: @unchecked
265-
selfId.code shouldBe "self"
266-
264+
appendCallTemplate.methodFullName shouldBe "<operator>.joernBufferAppend"
265+
val List(appendCallArgOne, appendCallArgTwo: Call) = appendCallTemplate.argument.l: @unchecked
267266
appendCallArgOne.code shouldBe "joern__inner_buffer"
268267
appendCallArgTwo.code shouldBe "<%= form.text_field :name %>"
269268
appendCallArgTwo.methodFullName shouldBe RubyOperators.templateOutEscape

0 commit comments

Comments
 (0)