Skip to content

[SR-5582] Changed NSString.appendingPathComponent implementation on Lin… #1294

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

Merged
merged 1 commit into from
Nov 8, 2017
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
19 changes: 5 additions & 14 deletions Foundation/NSPathUtilities.swift
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -82,13 +82,13 @@ internal extension String {
}

internal func _stringByAppendingPathComponent(_ str: String, doneAppending : Bool = true) -> String {
if str.length == 0 {
if str.isEmpty {
return self
}
if self == "" {
return "/" + str
if isEmpty {
return str
}
if self == "/" {
if hasSuffix("/") {
return self + str
}
return self + "/" + str
Expand Down Expand Up @@ -237,16 +237,7 @@ public extension NSString {
}

internal func _stringByAppendingPathComponent(_ str: String, doneAppending : Bool = true) -> String {
if str.length == 0 {
return _swiftObject
}
if self == "" {
return "/" + str
}
if self == "/" {
return _swiftObject + str
}
return _swiftObject + "/" + str
return _swiftObject._stringByAppendingPathComponent(str, doneAppending: doneAppending)
}

public func appendingPathComponent(_ str: String) -> String {
Expand Down
27 changes: 27 additions & 0 deletions TestFoundation/TestNSString.swift
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ class TestNSString : XCTestCase {
("test_initializeWithFormat", test_initializeWithFormat),
("test_initializeWithFormat2", test_initializeWithFormat2),
("test_initializeWithFormat3", test_initializeWithFormat3),
("test_appendingPathComponent", test_appendingPathComponent),
("test_deletingLastPathComponent", test_deletingLastPathComponent),
("test_getCString_simple", test_getCString_simple),
("test_getCString_nonASCII_withASCIIAccessor", test_getCString_nonASCII_withASCIIAccessor),
Expand Down Expand Up @@ -752,6 +753,32 @@ class TestNSString : XCTestCase {
XCTAssertEqual(string, "NSDictionary value is 1000 (42&0)")
}
}

func test_appendingPathComponent() {
do {
let path: NSString = "/tmp"
let result = path.appendingPathComponent("scratch.tiff")
XCTAssertEqual(result, "/tmp/scratch.tiff")
}

do {
let path: NSString = "/tmp/"
let result = path.appendingPathComponent("scratch.tiff")
XCTAssertEqual(result, "/tmp/scratch.tiff")
}

do {
let path: NSString = "/"
let result = path.appendingPathComponent("scratch.tiff")
XCTAssertEqual(result, "/scratch.tiff")
}

do {
let path: NSString = ""
let result = path.appendingPathComponent("scratch.tiff")
XCTAssertEqual(result, "scratch.tiff")
}
}

func test_deletingLastPathComponent() {
do {
Expand Down