Skip to content

Commit 321bec6

Browse files
Merge pull request #499 from EvotecIT/FixForJavascript
2 parents 67351d4 + f8e8e50 commit 321bec6

File tree

2 files changed

+24
-0
lines changed

2 files changed

+24
-0
lines changed
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
Import-Module .\PSWriteHTML.psd1 -Force
2+
3+
$test = "<test>"
4+
New-HTML {
5+
New-HTMLTableOption -DataStore JavaScript -BoolAsString -ArrayJoinString '<br>' -ArrayJoin
6+
7+
New-HTMLTab -Name 'Forest' {
8+
New-HTMLSection -HeaderText 'Summary' {
9+
New-HTMLTable -DataTable $test
10+
}
11+
}
12+
} -ShowHTML -FilePath "$PSScriptRoot\Example-TableWithTags.html" -Online

Public/New-HTMLTable.ps1

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1321,6 +1321,12 @@
13211321
ArrayJoinString = $Script:HTMLSchema['TableOptions']['DataStoreOptions'].ArrayJoinString
13221322
}
13231323
$DataToInsert = $Table | ConvertTo-PrettyObject @convertToPrettyObjectSplat | ConvertTo-Json
1324+
if (-not $InvokeHTMLTags) {
1325+
# If InvokeHTMLTags is not set, we need to escape HTML characters
1326+
# By default HTML tags are escaped when using DataStore HTML, but not when using JavaScript
1327+
# So we need to escape them here, so they don't break the JavaScript code
1328+
$DataToInsert = $DataToInsert -replace "<", "&lt;" -replace ">", "&gt;"
1329+
}
13241330
if ($DataToInsert.StartsWith('[')) {
13251331
$Script:HTMLSchema.CustomFooterJS[$DataStoreID] = "var $DataStoreID = $DataToInsert;"
13261332
} else {
@@ -1341,6 +1347,12 @@
13411347
ArrayJoinString = $Script:HTMLSchema['TableOptions']['DataStoreOptions'].ArrayJoinString
13421348
}
13431349
$DataToInsert = $Table | ConvertTo-PrettyObject @convertToPrettyObjectSplat | ConvertTo-Json
1350+
if (-not $InvokeHTMLTags) {
1351+
# If InvokeHTMLTags is not set, we need to escape HTML characters
1352+
# By default HTML tags are escaped when using DataStore HTML, but not when using JavaScript
1353+
# So we need to escape them here, so they don't break the JavaScript code
1354+
$DataToInsert = $DataToInsert -replace "<", "&lt;" -replace ">", "&gt;"
1355+
}
13441356
if ($DataToInsert.StartsWith('[')) {
13451357
$Options = $Options.Replace('"markerForDataReplacement"', $DataToInsert)
13461358
} else {

0 commit comments

Comments
 (0)