@@ -55,24 +55,30 @@ internal extension String {
55
55
56
56
internal var _startOfPathExtension : String . Index ? {
57
57
precondition ( !hasSuffix( " / " ) )
58
-
59
- var curPos = endIndex
60
- let lastCompStartPos = _startOfLastPathComponent
61
-
58
+
59
+ var currentPosition = endIndex
60
+ let startOfLastPathComponent = _startOfLastPathComponent
61
+
62
62
// Find the beginning of the extension
63
- while curPos > lastCompStartPos {
64
- let prevPos = index ( before: curPos )
65
- let char = self [ prevPos ]
66
- if char == " / " {
63
+ while currentPosition > startOfLastPathComponent {
64
+ let previousPosition = index ( before: currentPosition )
65
+ let character = self [ previousPosition ]
66
+ if character == " / " {
67
67
return nil
68
- } else if char == " . " {
69
- if lastCompStartPos == prevPos {
68
+ } else if character == " . " {
69
+ if startOfLastPathComponent == previousPosition {
70
+ return nil
71
+ } else if case let previous2Position = index ( before: previousPosition) ,
72
+ previousPosition == index ( before: endIndex) &&
73
+ previous2Position == startOfLastPathComponent &&
74
+ self [ previous2Position] == " . "
75
+ {
70
76
return nil
71
77
} else {
72
- return curPos
78
+ return currentPosition
73
79
}
74
80
}
75
- curPos = prevPos
81
+ currentPosition = previousPosition
76
82
}
77
83
return nil
78
84
}
@@ -262,7 +268,7 @@ public extension NSString {
262
268
if fixedSelf. length <= 1 {
263
269
return fixedSelf
264
270
}
265
- if let extensionPos = ( fixedSelf. _startOfPathExtension) {
271
+ if let extensionPos = fixedSelf. _startOfPathExtension {
266
272
return String ( fixedSelf. prefix ( upTo: fixedSelf. index ( before: extensionPos) ) )
267
273
} else {
268
274
return fixedSelf
0 commit comments