Skip to content

Commit

Permalink
fix: properly quote labels with dots
Browse files Browse the repository at this point in the history
Dots are not supported anymore in labels.
This commit ensures strings with dots are properly quoted in the
generated mermaid code.
  • Loading branch information
derlin committed Aug 2, 2024
1 parent 4e76d1a commit a6a5e35
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 4 deletions.
1 change: 0 additions & 1 deletion .github/workflows/main.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ name: Test and build
# events but only for the master branch
on:
push:
branches: [ 'develop', 'main' ]
pull_request:
branches: [ main ]

Expand Down
2 changes: 1 addition & 1 deletion src/main/kotlin/ch/derlin/dcvizmermaid/graph/Utils.kt
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,5 @@ internal fun Any.toValidId(): String = toString().replace("[^a-zA-Z0-9]".toRegex

internal fun Any.toValidName() =
toString().replace("\"", "'").let {
if ("[\\w !?_/':,.-]*".toRegex().matchEntire(it) == null) "\"$it\"" else it
if ("[\\w !?_/':,-]*".toRegex().matchEntire(it) == null) "\"$it\"" else it
}
2 changes: 1 addition & 1 deletion src/test/kotlin/ch/derlin/dcvizmermaid/graph/UtilsTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class UtilsTest {
mapOf(
// no quotes
"node" to "node",
"/path/to/file.txt" to "/path/to/file.txt",
"/path/to/file.txt" to "\"/path/to/file.txt\"",
"some node" to "some node",
"some-node ?" to "some-node ?",
// quotes
Expand Down
11 changes: 10 additions & 1 deletion src/test/kotlin/ch/derlin/dcvizmermaid/renderers/TestUtils.kt
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,17 @@ fun dummyGraph(): String =
"""
services:
web:
image: derlin/rickroller
image: derlin/rickroller:latest
ports:
- 8080:80
volumes:
- ./foo.conf:/data/.foo.conf
- settings:/settings
volumes:
settings:
""".trimIndent(),
withPorts = true,
withVolumes = true,
).build()

fun tmpFileWithExtension(extension: String) = File.createTempFile("test", extension).also { it.deleteOnExit() }
Expand Down

0 comments on commit a6a5e35

Please sign in to comment.