Skip to content

Commit db0e339

Browse files
committed
🐛 Several fixes
- account for the difference between `[IO.Path]::Combine()` and `Join-Path` - fix core safe char encoding behavior - fix test fields
1 parent 1ebb3f9 commit db0e339

4 files changed

+27
-6
lines changed

Convert-Xml.ps1

+1-1
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ Process
7777
}
7878
else
7979
{
80-
$absOutFile = Join-Path "$PWD" $OutFile
80+
$absOutFile = if((Split-Path $OutFile -IsAbsolute)) {$OutFile} else {Join-Path "$PWD" $OutFile}
8181
if((Test-Path $absOutFile) -and
8282
!$PSCmdlet.ShouldContinue("$(Get-Item $absOutFile |Select-Object FullName,LastWriteTime,Length)","Overwrite File?"))
8383
{Write-Warning "Skipping transform from $absPath to $OutFile"; return}

ConvertFrom-EscapedXml.ps1

+2-2
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,9 @@ ConvertFrom-EscapedXml.ps1 '<a href="http://example.org">link&lt
2020
#Requires -Version 2
2121
[CmdletBinding()][OutputType([string])] Param(
2222
# The escaped XML text.
23-
[Parameter(Mandatory=$true,Position=0,ValueFromPipeline=$true)][string]$EscapedXml,
23+
[Parameter(Mandatory=$true,Position=0,ValueFromPipeline=$true)][string] $EscapedXml,
2424
# Outputs the XML without indentation.
25-
[Alias('NoIndent')][switch]$Compress
25+
[Alias('NoIndent')][switch] $Compress
2626
)
2727
Process
2828
{

ConvertTo-SafeEntities.ps1

+23-2
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,27 @@ ETA: ½ hour
3737
An HTML or XML string that may include emoji or other Unicode characters outside
3838
the 7-bit ASCII range.
3939
#>
40-
[Parameter(Position=0,Mandatory=$true,ValueFromPipeline=$true)][string] $InputObject
40+
[Parameter(Position=0,Mandatory=$true,ValueFromPipeline=$true)][string] $InputObject,
41+
# Indicates that markdown characters should also be escaped.
42+
[switch] $IncludeMarkupChars
4143
)
42-
Process {return [Text.Encodings.Web.HtmlEncoder]::Default.Encode($InputObject)}
44+
Process
45+
{
46+
if($IncludeMarkupChars) {return [Text.Encodings.Web.HtmlEncoder]::Default.Encode($InputObject)}
47+
else
48+
{
49+
[char[]] $chars =
50+
for ($i = 0; $i -lt $InputObject.Length; $i++)
51+
{
52+
[int] $c = [char]$InputObject[$i]
53+
Write-Verbose "$i : $c"
54+
if([char]::IsSurrogatePair($InputObject,$i))
55+
{ ('&#x{0:X};' -f [char]::ConvertToUtf32($InputObject,$i++)).GetEnumerator() }
56+
elseif(0x7F -lt $c)
57+
{ ('&#x{0:X};' -f $c).GetEnumerator() }
58+
else
59+
{ [char]$c }
60+
}
61+
return New-Object String $chars,0,$chars.Length
62+
}
63+
}

test/ConvertFrom-EscapedXml.Tests.ps1

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ Describe 'ConvertFrom-EscapedXml' -Tag ConvertFrom-EscapedXml -Skip:$skip {
1313
if($scriptsdir -notin ($env:Path -split $sep)) {$env:Path += "$sep$scriptsdir"}
1414
}
1515
Context 'Parse escaped XML into XML and serialize it' -Tag ConvertFromEscapedXml,Convert,ConvertFrom,EscapedXml,Xml {
16-
It "Should convert '<Input>' into '<Output>'" -TestCases @(
16+
It "Should convert '<Value>' into '<Result>'" -TestCases @(
1717
@{ Value = '&lt;x /&gt;'; Result = '<x />' }
1818
@{ Value = '&lt;a href=&quot;http://example.org&quot;&gt;link&lt;/a&gt;'
1919
Result = '<a href="http://example.org">link</a>' }

0 commit comments

Comments
 (0)