Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

### Fixed
- **Literal path handling for JSON inputs and diagram output.** `Import-Inventory`,
SNMP credential-map readers, `Compare-NetworkScans` metadata inputs, and
`Export-DrawIO` now use `-LiteralPath` so paths containing `[]` or other
wildcard metacharacters work on all platforms.

## [1.4.0] - 2026-09-09

### Added
Expand Down
6 changes: 3 additions & 3 deletions NetDiagram-PS/Public/Compare-NetworkScans.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,9 @@ function Compare-NetworkScans {

# Load files (topology via Import-Topology for validation)
try {
$baseMeta = Get-Content -Path $BaselineMetadata -Raw | ConvertFrom-Json
$baseMeta = Get-Content -LiteralPath $BaselineMetadata -Raw | ConvertFrom-Json
$baseTopoData = Import-Topology -Path $BaselineTopology
$currMeta = Get-Content -Path $CurrentMetadata -Raw | ConvertFrom-Json
$currMeta = Get-Content -LiteralPath $CurrentMetadata -Raw | ConvertFrom-Json
$currTopoData = Import-Topology -Path $CurrentTopology
}
catch {
Expand Down Expand Up @@ -195,7 +195,7 @@ function Compare-NetworkScans {

if ($OutFile) {
try {
$reportText | Out-File -FilePath $OutFile -Encoding utf8 -Force
$reportText | Out-File -LiteralPath $OutFile -Encoding utf8 -Force
Write-Verbose "Comparison report written to $OutFile"
}
catch {
Expand Down
2 changes: 1 addition & 1 deletion NetDiagram-PS/Public/Export-DrawIO.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,7 @@ function Export-DrawIO {

# Write to file
try {
$xml.ToString() | Out-File -FilePath $OutFile -Encoding utf8 -Force
$xml.ToString() | Out-File -LiteralPath $OutFile -Encoding utf8 -Force
Write-Verbose "Exported diagram to $OutFile"
}
catch {
Expand Down
4 changes: 2 additions & 2 deletions NetDiagram-PS/Public/Get-SnmpBridgeNeighbors.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,12 @@ function Get-SnmpBridgeNeighbors {
throw "Invalid topology object"
}

if (-not (Test-Path -Path $CredentialMapPath -PathType Leaf)) {
if (-not (Test-Path -LiteralPath $CredentialMapPath -PathType Leaf)) {
throw "Credential map file not found: $CredentialMapPath"
}

try {
$credMap = Get-Content -Path $CredentialMapPath -Raw | ConvertFrom-Json
$credMap = Get-Content -LiteralPath $CredentialMapPath -Raw | ConvertFrom-Json
}
catch {
throw "Failed to parse credential map JSON: $_"
Expand Down
4 changes: 2 additions & 2 deletions NetDiagram-PS/Public/Get-SnmpNeighbors.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -73,12 +73,12 @@ function Get-SnmpNeighbors {
throw "Invalid topology object"
}

if (-not (Test-Path -Path $CredentialMapPath -PathType Leaf)) {
if (-not (Test-Path -LiteralPath $CredentialMapPath -PathType Leaf)) {
throw "Credential map file not found: $CredentialMapPath"
}

try {
$credMap = Get-Content -Path $CredentialMapPath -Raw | ConvertFrom-Json
$credMap = Get-Content -LiteralPath $CredentialMapPath -Raw | ConvertFrom-Json
}
catch {
throw "Failed to parse credential map JSON: $_"
Expand Down
4 changes: 2 additions & 2 deletions NetDiagram-PS/Public/Import-Inventory.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,12 @@ function Import-Inventory {
)

process {
if (-not (Test-Path -Path $Path -PathType Leaf)) {
if (-not (Test-Path -LiteralPath $Path -PathType Leaf)) {
throw "Inventory file not found: $Path"
}

try {
$inventory = Get-Content -Path $Path -Raw | ConvertFrom-Json
$inventory = Get-Content -LiteralPath $Path -Raw | ConvertFrom-Json
}
catch {
throw "Failed to parse inventory JSON: $_"
Expand Down
33 changes: 33 additions & 0 deletions tests/NetDiagram.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,15 @@ Describe 'Import-Inventory' {
{ Import-Inventory -Path 'C:\NonExistent\file.json' } | Should -Throw
}

It 'Reads inventory paths that contain wildcard metacharacters literally' {
$path = Join-Path $TestDrive 'inventory[bracket].json'
'{"knownDevices":[{"ip":"10.0.0.5","hostname":"bracket-host"}]}' | Set-Content -LiteralPath $path

$topology = Import-Inventory -Path $path
$topology.Nodes | Should -HaveCount 1
$topology.Nodes[0].IP | Should -Be '10.0.0.5'
}

It 'Accepts a valid empty inventory' {
$path = Join-Path $TestDrive 'empty-inventory.json'
'{"knownDevices":[],"subnets":[]}' | Set-Content -Path $path
Expand Down Expand Up @@ -491,6 +500,30 @@ Describe 'Export-DrawIO' {
# Try to load as XML to verify it's valid
{ [xml](Get-Content -Path $drawioPath -Raw) } | Should -Not -Throw
}

It 'Escapes XML metacharacters in node labels and attributes' {
$path = Join-Path $TestDrive 'xml-special.json'
@{
knownDevices = @(
@{
ip = '10.0.0.99'
hostname = 'host<script>&"quote"'
role = 'server'
vendor = 'Acme & Co'
}
)
} | ConvertTo-Json -Depth 10 | Set-Content -LiteralPath $path

$topology = Import-Inventory -Path $path
$drawioPath = Join-Path $TestDrive 'xml-special[1].drawio'
$topology | Export-DrawIO -OutFile $drawioPath -Force

$xml = [xml](Get-Content -LiteralPath $drawioPath -Raw)
$node = $xml.SelectSingleNode("//UserObject[@ip='10.0.0.99']")
$node | Should -Not -BeNullOrEmpty
$node.hostname | Should -Be 'host<script>&"quote"'
$node.vendor | Should -Be 'Acme & Co'
}
}

Describe 'Export-Metadata' {
Expand Down