Skip to content

Commit af8548a

Browse files
committed
Update normalisation code
1 parent 9867175 commit af8548a

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

Sources/SWBUtil/Path.swift

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,13 @@ private extension String.UTF8View {
3838
public struct Path: Serializable, Sendable {
3939
private var _impl: FilePath
4040

41+
private init(_ impl: FilePath) {
42+
self._impl = impl
43+
}
44+
4145
public var str: String {
4246
_impl.string
4347
}
44-
4548
/// The system path separator.
4649
#if os(Windows)
4750
public static let pathSeparator = Character("\\")
@@ -343,7 +346,12 @@ public struct Path: Serializable, Sendable {
343346
///
344347
/// - parameter removeDotDotFromRelativePath: If false, then '..' will not be removed from relative paths, akin to the behavior of `-[NSString stringByStandardizingPath]`.
345348
public func normalize(removeDotDotFromRelativePath: Bool = true) -> Path {
346-
Path(_impl.lexicallyNormalized().string)
349+
if !removeDotDotFromRelativePath && !isAbsolute {
350+
let pathComponents = str.split(separator: Path.pathSeparator)
351+
.filter { !$0.isEmpty && $0 != "." }
352+
return Path(pathComponents.joined(separator: String(Path.pathSeparator)))
353+
}
354+
return Path(_impl.lexicallyNormalized())
347355
}
348356

349357
/// Check if the path is currently normalized.

0 commit comments

Comments
 (0)