Skip to content

Commit

Permalink
Don't discard type names with parenthesis unless they're enclosed in …
Browse files Browse the repository at this point in the history
…parentheses from both sidews

- Only `(example_name)` is not allowed, `(example_name` and `example_name)` are now considered valid
  • Loading branch information
DelevoXDG committed Mar 15, 2024
1 parent f0d8a8a commit 7695f27
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ data class TypedData private constructor(
customTypes.keys.forEach {
require(it.isNotEmpty()) { "Type names cannot be empty." }
require(!it.isArray()) { "Type names cannot end in *. [$it] was found." }
require(!it.startsWith("(") && !it.endsWith(")")) { "Type names cannot be enclosed in parentheses. [$it] was found." }
require(!it.isEnum()) { "Type names cannot be enclosed in parentheses. [$it] was found." }
require(!it.contains(",")) { "Type names cannot contain commas. [$it] was found." }
require(it in referencedTypes) { "Dangling types are not allowed. Unreferenced type [$it] was found." }
}
Expand Down
10 changes: 4 additions & 6 deletions lib/src/test/kotlin/starknet/data/TypedDataTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -469,13 +469,11 @@ internal class TypedDataTest {

@Test
fun `type with parentheses`() {
val types = listOf("(left", "right)", "(both)")
types.forEach { type ->
val exception = assertThrows<IllegalArgumentException> {
makeTypedData(Revision.V1, type)
}
assertEquals("Type names cannot be enclosed in parentheses. [$type] was found.", exception.message)
val type = "(mytype)"
val exception = assertThrows<IllegalArgumentException> {
makeTypedData(Revision.V1, type)
}
assertEquals("Type names cannot be enclosed in parentheses. [$type] was found.", exception.message)
}

@Test
Expand Down

0 comments on commit 7695f27

Please sign in to comment.