-
Notifications
You must be signed in to change notification settings - Fork 129
TSCBasic: protect against an invalid API usage #325
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,6 +18,11 @@ private typealias PathImpl = UNIXPath | |
private typealias PathImpl = UNIXPath | ||
#endif | ||
|
||
#if canImport(Darwin) | ||
import Darwin.C | ||
#endif | ||
|
||
import class Foundation.NSURL | ||
import protocol Foundation.CustomNSError | ||
import var Foundation.NSLocalizedDescriptionKey | ||
|
||
|
@@ -254,7 +259,18 @@ public struct RelativePath: Hashable { | |
/// normalization or canonicalization. This will construct a path without | ||
/// an anchor and thus may be invalid. | ||
fileprivate init(unsafeUncheckedPath string: String) { | ||
self.init(PathImpl(string: string)) | ||
if string.isEmpty { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. does the case need to be a guard and then return a ~const empty representation? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We can change that of course, but that doesn't help the macOS case. It would be purely a syntactic change and should be equivalent to this. |
||
self.init(PathImpl(string: string)) | ||
} else { | ||
#if _runtime(_ObjC) | ||
self.init(PathImpl(string: String(cString: NSURL(fileURLWithPath: string).fileSystemRepresentation))) | ||
#else | ||
let normalized: UnsafePointer<Int8> = string.fileSystemRepresentation | ||
defer { normalized.deallocate() } | ||
|
||
self.init(PathImpl(string: String(cString: normalized))) | ||
#endif | ||
} | ||
} | ||
|
||
/// Initializes the RelativePath from `str`, which must be a relative path | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
does the case need to be a guard and then return a ~const empty representation?