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
50 changes: 50 additions & 0 deletions External/domainName-4282008.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
function Test-ValidDomainName
{
<#
.SYNOPSIS
Tests whether a string is a valid domain name.

.DESCRIPTION
Test-ValidDomainName uses a regular expression match to test whether DomainName is a valid domain name. The match pattern is the generally-accepted regular expression from http://stackoverflow.com/a/20204811/1404637

.OUTPUTS
Returns true when DomainName is a valid domain name. Returns false otherwise.

.EXAMPLE
'as-d.jkl' | Test-ValidDomainName
# true

as-d.jkl is a valid domain name.

.EXAMPLE
'-asd.jkl' | Test-ValidDomainName
# false

Labels cannot start or end with hyphen.

.LINK
http://stackoverflow.com/a/20204811/1404637
#>
[CmdletBinding()]
param
(
# The domain name to test for validity.
[Parameter(Mandatory = $true,
Position = 1,
ValueFromPipeline = $true)]
[AllowEmptyString()]
[string]
$DomainName
)
process
{
# http://stackoverflow.com/a/20204811/1404637

if ( $DomainName -notmatch '(?=^.{4,253}$)(^((?!-)[a-zA-Z0-9-]{1,63}(?<!-)\.)+[a-zA-Z]{2,63}$)' )
{
&(Publish-Failure "$DomainName is not a valid domain name.",'DomainName' ([System.ArgumentException]))
return $false
}
return $true
}
}
10 changes: 7 additions & 3 deletions Functions/path.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,14 @@ Describe Test-FolderPathsAreEqual {
@('c:\folder1', 'c:\folder2', $false),
@('c:\folder\', 'c:/folder', $true),
@('c:/folder', 'c:\folder', $true),
@('c:/folder1', 'c:/folder2', $false)
@('c:/folder1', 'c:/folder2', $false),
@('\\server.net\share','\\server.net\share\', $true),
@('file://server.net/share','\\server.net\share', $true)
)
foreach ( $value in $values )
{
$a,$b,$expected = $value
It "$b -eq $b is $expected" {
It "$a -eq $b is $expected" {
$r = Test-FolderPathsAreEqual $a $b
$r | Should be $expected
}
Expand All @@ -25,7 +27,9 @@ Describe ConvertTo-WindowsShellFolderPathFormat {
@('c:\folder', 'c:\folder'),
@('c:/folder', 'c:\folder'),
@('c:\folder\','c:\folder'),
@('c:\\folder','c:\folder')
@('c:\\folder','c:\folder'),
@('\\server.net\share\','\\server.net\share'),
@('file://server.net/share','\\server.net\share')
)
foreach ( $value in $values )
{
Expand Down
2 changes: 1 addition & 1 deletion Functions/path.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ function ConvertTo-WindowsShellFolderPathFormat
process
{
$splat = @{
FilePathType = 'Windows'
Scheme = 'plain'
TrailingSlash = $false
}
return $InputPath |
Expand Down
10 changes: 9 additions & 1 deletion Functions/shellLibraryFolder.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,15 @@ function Test-ShellLibraryFolder
# load the library
$l = [Microsoft.WindowsAPICodePack.Shell.ShellLibrary]::Load($LibraryName,$true)

if ( -not ($FolderPath | Test-Path -PathType Container -ea Stop ) )
# safely test if the path exists
try
{
# Test-Path can throw an exception for UNC paths
$folderPathExists = $FolderPath | Test-Path -PathType Container
}
catch {}

if ( -not ( $folderPathExists ) )
{
# the file system folder does not exist
# search through the list of folders
Expand Down
6 changes: 6 additions & 0 deletions IntegrationTests/shellLibraryFolder.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,12 @@ Describe Test-ShellLibraryFolder {
$r | Should be $false
}
}
Context 'the folder does not exist and neither does the file system folder (UNC)' {
It 'returns false' {
$r = '\\serverc41f5bdb.net\path' | Test-ShellLibraryFolder $libraryName
$r | Should be $false
}
}
Context 'library doesn''t exist' {
It 'remove the library' {
Invoke-ProcessShellLibrary Set Absent $libraryName
Expand Down