Skip to content

Commit

Permalink
Merge pull request #654 from unni-dm/main
Browse files Browse the repository at this point in the history
Fix for HTML result will break when context data key has special char…
  • Loading branch information
takahirom authored Feb 12, 2025
2 parents 777f8c7 + 6f69930 commit a8d1d20
Showing 1 changed file with 13 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -92,18 +92,29 @@ data class CaptureResults(
"<ul class=\"tabs\">"
)
tabs.forEachIndexed { tabIndex, tab ->
val updatedKey = cleanId(tab.id)
// <li class="tab col s3"><a href="#test1">Test 1</a></li>
val activeClass = if (tabIndex == 0) """class="active" """ else ""
append("""<li class="tab"><a $activeClass href="#${tab.id}">${tab.title}</a></li>""")
append("""<li class="tab"><a $activeClass href="#${updatedKey}">${tab.title}</a></li>""")
}
append("</ul>\n</div>")
tabs.forEach { tab ->
append("""<div id="${tab.id}" class="col s12" style="display: none;">${tab.contents}</div>""")
val updatedKey = cleanId(tab.id)
append("""<div id="$updatedKey" class="col s12" style="display: none;">${tab.contents}</div>""")
}
append("</div>")
}
}

/**
* Function which remove all potential special characters from id
* which will break HTML result
*/
private fun cleanId(dynamicString: String): String {
val stringWithoutSpace = Regex("\\s+").replace(dynamicString, "-")
return Regex("[^\\w.:-]").replace(stringWithoutSpace, "")
}

private fun String.pathFrom(reportDirectoryPath: String): String {
val reportDirectory = Path(reportDirectoryPath)
val relativePath = Path(this).relativeTo(reportDirectory)
Expand Down

0 comments on commit a8d1d20

Please sign in to comment.