Skip to content

Commit da60c02

Browse files
committed
Add Empty Case To isValidFilename
1 parent d87ae91 commit da60c02

File tree

2 files changed

+4
-3
lines changed

2 files changed

+4
-3
lines changed

CodeEdit/Utils/Extensions/String/String+ValidFileName.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@ extension CharacterSet {
1313
}
1414

1515
extension String {
16-
/// On macOS, valid file names must not contain the `NULL` or `:` characters and must be less than
17-
/// 256 UTF16 characters.
16+
/// On macOS, valid file names must not contain the `NULL` or `:` characters, must be non-empty, and must be less
17+
/// than 256 UTF16 characters.
1818
var isValidFilename: Bool {
19-
CharacterSet(charactersIn: self).isDisjoint(with: .invalidFileNameCharacters) && utf16.count < 256
19+
!isEmpty && CharacterSet(charactersIn: self).isDisjoint(with: .invalidFileNameCharacters) && utf16.count < 256
2020
}
2121
}

CodeEditTests/Utils/UnitTests_Extensions.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,7 @@ final class CodeEditUtilsExtensionsUnitTests: XCTestCase {
166166
func testInvalidFileName() {
167167
// The only limitations for macOS file extensions is no ':' and no NULL characters and 255 UTF16 char limit.
168168
let invalidCases = [
169+
"",
169170
":",
170171
"\0",
171172
"Hell\0 World!",

0 commit comments

Comments
 (0)