Skip to content

Commit

Permalink
[Nu-7231] Do not allow inline maps with non string keys
Browse files Browse the repository at this point in the history
  • Loading branch information
DeamonDev authored and Piotr Rudnicki committed Dec 18, 2024
1 parent ace3d3c commit 69174ff
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,12 @@ class FragmentParameterTypingParser(classLoader: ClassLoader, classDefinitions:
val setPattern = "Set\\[(.+)\\]".r

Try(className match {
case mapPattern(x, y) =>
case mapPattern(x, y) if x == "String" =>
val resolvedFirstTypeParam = resolveInnerClass(x)
val resolvedSecondTypeParam = resolveInnerClass(y)
Typed.genericTypeClass[java.util.Map[_, _]](List(resolvedFirstTypeParam, resolvedSecondTypeParam))
case mapPattern(_, _) =>
throw new IllegalArgumentException("Obtained map with non string key")
case listPattern(x) =>
val resolvedTypeParam = resolveInnerClass(x)
Typed.genericTypeClass[java.util.List[_]](List(resolvedTypeParam))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1160,6 +1160,35 @@ class NodeDataValidatorSpec extends AnyFunSuite with Matchers with Inside with T
}
}

test("should not allow creation of inline map with non string keys in FragmentInputDefinition") {
val nodeId: String = "in"
val paramName = "param1"

inside(
validate(
FragmentInputDefinition(
nodeId,
List(
FragmentParameter(
ParameterName(paramName),
FragmentClazzRef("Map[Long, Double]"),
required = false,
initialValue = None,
hintText = None,
valueEditor = None,
valueCompileTimeValidation = None
)
),
),
ValidationContext.empty,
Map.empty,
outgoingEdges = List(OutgoingEdge("any", Some(FragmentOutput("out1"))))
)
) { case ValidationPerformed(errors, None, None) =>
errors shouldBe List(FragmentParamClassLoadError(ParameterName("param1"), "Map[Long, Double]", "in"))
}
}

test(
"should not allow usage of generic type in FragmentInputDefinition parameter when occurring type is not on classpath"
) {
Expand Down

0 comments on commit 69174ff

Please sign in to comment.