Skip to content
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

[SR-2581] URL.lastPathComponent returns the current working directory for empty file URL #4114

Closed
WFT opened this issue Sep 8, 2016 · 6 comments

Comments

@WFT
Copy link

WFT commented Sep 8, 2016

Previous ID SR-2581
Radar None
Original Reporter @WFT
Type Bug
Status Closed
Resolution Invalid
Environment

OS X El Capitan 10.11.6, Xcode 8 GM, Swift 3.0.

Additional Detail from JIRA
Votes 0
Component/s Foundation
Labels Bug, 3.0Regression, SDKOverlay
Assignee None
Priority Medium

md5: ac45d0d3490a3144fcfec1d7a03f04d4

Issue Description:

I saw this both in the REPL and when compiling a file.

1> import Foundation
2> URL(fileURLWithPath: "").lastPathComponent
$R0: String = "testing"

NSURL(fileURLWithPath: "").lastPathComponent just returns nil.

This seems bugs.swift.org-y to me since it has to do with one of the new value-types, but I don't have easy access to an Ubuntu machine to test it on at the moment. Please let me know if I should refile as a radar instead.

Possibly related to SR-2591 — see the comments below.

@belkadan
Copy link

belkadan commented Sep 8, 2016

Mine returns "swift", which I think means it's returning garbage.

@WFT
Copy link
Author

WFT commented Sep 8, 2016

Interesting. I ran into another garbage NSString/String problem with URL at the same time. I didn't think they were the same thing because this consistently returns "testing" for me, whereas that one seems like it's just reading random bytes from the heap. I'll create a new issue for that and link it here.

@WFT
Copy link
Author

WFT commented Sep 8, 2016

Anyway, I also tested this issue in Objective-C (using the macOS 10.12 SDK) and wasn't able to reproduce it.

@import Foundation;

int main() {
  NSString *s = [[NSURL fileURLWithPath: @""] lastPathComponent];
  NSLog(@"%lu", (unsigned long)s.length);
  // Logs "0"
}

@WFT
Copy link
Author

WFT commented Sep 8, 2016

The possibly related issue is SR-2591.

@WFT
Copy link
Author

WFT commented Sep 9, 2016

Oops, never mind — I think this returns the lastPathComponent of the current working directory. URL(fileURLWithPath: "") might be the root cause here. That call produces this: {{ URL = "./ – ile:///Users/field-thompson/dev/testing/" }} . I think that's the wrong way to display the URL and it's a little surprising seeing as it's a change in behavior, but it's correct according to the doc comment, so I'll close this bug.

@belkadan
Copy link

belkadan commented Sep 9, 2016

Aha, we're treating it as a relative URL. I still think we should attempt to do the same thing as NSURL, though. @phausler?

@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 2022
@shahmishal shahmishal transferred this issue from apple/swift May 5, 2022
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants