forked from nightroman/PowerShellTraps
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.3.escaped.ps1
More file actions
46 lines (38 loc) · 881 Bytes
/
test.3.escaped.ps1
File metadata and controls
46 lines (38 loc) · 881 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
$ErrorActionPreference = 'Stop'
# set location to this script directory
$PSScriptRoot = Split-Path $MyInvocation.MyCommand.Definition
Set-Location -LiteralPath $PSScriptRoot
# make the directory "test[" and the script "test.ps1" in it
$null = mkdir test[ -Force
Set-Content -LiteralPath test[\test.ps1 -Value 42
# Test 1. This works in v2-v6 and fails in v7
try {
& "$PSScriptRoot\test``[\test.ps1"
}
catch {
$_
}
# Test 2. This works in v5+ and fails v2, v3, v4.
# It is not clear though why it needs two backticks in v5.
try {
& '.\test``[\test.ps1'
}
catch {
$_
}
# Test 3. This works in v5+ and fails v2, v3, v4.
# The expandable string requires 4 backticks in v5.
try {
& ".\test````[\test.ps1"
}
catch {
$_
}
# Test 4. For some reason 5 backticks also work in v5+.
try {
& ".\test`````[\test.ps1"
}
catch {
$_
}
Remove-Item -LiteralPath test[ -Force -Recurse