From f75a8adc21b6976087a5e844ee27ce98f5b30dbf Mon Sep 17 00:00:00 2001 From: Shawn Masterson Date: Sun, 28 Dec 2025 14:22:15 -0500 Subject: [PATCH] fix: optimize JSON conversion and regex handling in percentage bar rendering --- Private/New-TablePercentageBarInternal.ps1 | 4 ++-- Public/New-HTMLTable.ps1 | 7 ++++++- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/Private/New-TablePercentageBarInternal.ps1 b/Private/New-TablePercentageBarInternal.ps1 index 3ace8a62..7803641e 100644 --- a/Private/New-TablePercentageBarInternal.ps1 +++ b/Private/New-TablePercentageBarInternal.ps1 @@ -59,7 +59,7 @@ ) if ($ConditionalFormatting) { - $JsonConditions = $ConditionalFormatting | ConvertTo-Json + $JsonConditions = $ConditionalFormatting | ConvertTo-Json -Compress [ordered]@{ targets = $ColumnID render = "`$.fn.dataTable.render.percentBar('$Type','$TextColor', '$BorderColor', '$BarColor', '$BackgroundColor', $RoundValue, '$BorderStyle', $JsonConditions)" @@ -70,4 +70,4 @@ render = "`$.fn.dataTable.render.percentBar('$Type','$TextColor', '$BorderColor', '$BarColor', '$BackgroundColor', $RoundValue, '$BorderStyle')" } } -} \ No newline at end of file +} diff --git a/Public/New-HTMLTable.ps1 b/Public/New-HTMLTable.ps1 index 75395fea..071bdcbd 100644 --- a/Public/New-HTMLTable.ps1 +++ b/Public/New-HTMLTable.ps1 @@ -1285,7 +1285,12 @@ # Before: "display": "$.fn.dataTable.Responsive.display.childRowImmediate" # After: "display": $.fn.dataTable.Responsive.display.childRowImmediate $Options = $Options -replace '"(\$\.fn\.dataTable\.Responsive\.display\.childRowImmediate)"', '$1' - $Options = $Options -replace '"(\$\.fn\.dataTable\.render\.percentBar\(.+\))"', '$1' + # $Options = $Options -replace '"(\$\.fn\.dataTable\.render\.percentBar\(.+\))"', '$1' + $Options = [regex]::Replace( + $Options, + '(?s)"(\$\.fn\.dataTable\.render\.percentBar\(.+?\))"', + { param($m) ($m.Groups[1].Value -replace '\\\"', '"' -replace '\\u0027', "'" ) } + ) # we need to cleanup $Options for columnDefs/render, remove \r\n #$Options = $Options -replace '\\r\\n', '\r\n' #-replace "\\`"",'"'