Skip to content

Commit

Permalink
Fix bug in which argument parsing was not correctly done
Browse files Browse the repository at this point in the history
  • Loading branch information
kevinvandenbreemen committed Nov 6, 2023
1 parent 4282977 commit 8738482
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class MacrosPlugin(private val macroRegistry: MacroRegistry): PageRenderingPlugi

val argMap: MutableMap<String, String> = mutableMapOf()
if(macro.groupValues[2].isNotEmpty()) {
val argumentsRaw = macro.groupValues[2].split("[\\s]*[,][\\s]*")
val argumentsRaw = macro.groupValues[2].split("[\\s]*[,][\\s]*".toRegex())
argumentsRaw.mapNotNull { argument ->
argument.split("=").let { rawPair ->
if(rawPair.size != 2) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ class MacrosPluginTest {

override fun execute(args: Map<String, String>): String {
val message = args["message"] ?: "(missing message)"
val additional = args["additional"]
if(additional != null) {
return "got pair: ${Pair<String, String>(message, additional).toString()}"
}
return "HiMsg: $message"
}
}
Expand Down Expand Up @@ -80,4 +84,22 @@ This is a special test.
rendered.shouldContain("HiMsg: (missing message)")
}

@Test
fun `should handle macros with multiple arguments`() {
val markdown = """
# Hello world
this is a test of some wiki content.
{@macro:HelloWorld message=Hi how are you?, additional=this/is/a/test}
This is a special test.
""".trimIndent()

val rendered = plugin.process(markdown)

println("RENDERED:\n===================\n$rendered")
rendered.shouldContain("got pair: (Hi how are you?, this/is/a/test)")
}

}

0 comments on commit 8738482

Please sign in to comment.