Skip to content

Fix String.deletingPathExtension Inconsistency #1376

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

Conversation

dduan
Copy link
Contributor

@dduan dduan commented Dec 20, 2017

The following code behaves differently on macOS and Linux:

NSString(string: "..").deletingPathExtension

On Linux, the resulting value is . while on macOS, it's ...

I think the latter make far more sense since .. mean parent directory,
treating the last dot as "extension" is a bit of a stretch. Plus, this
logic existed on macOS longer (therefore has more existing users). So it
make sense to align Linux Foundation's behavior to that of macOS.

JIRA: https://bugs.swift.org/browse/SR-6647

The following code behaves differently on macOS and Linux:

```swift
NSString(string: "..").deletingPathExtension
```

On Linux, the resulting value is `.` while on macOS, it's `..`.

I think the latter make far more sense since `..` mean parent directly,
treating the last dot as "extension" is a bit of a stretch. Plus, this
logic existed on macOS longer (therefore has more existing users). So it
make sense to align Linux Foundation's behavior to that of macOS.
@dduan dduan force-pushed the fix-deletingPathExtension-inconsistency branch 2 times, most recently from 3f392e9 to c171fed Compare December 20, 2017 21:28
@millenomi
Copy link
Contributor

Looks good to me, though maybe the variable names around this point — not just the one you're adding, the existing ones as well — could stand to be a little clearer :)

@dduan
Copy link
Contributor Author

dduan commented Dec 20, 2017

Thanks! I can work on that. The other issue I'm seeing is unrelated tests (in the compiler) failing on CI. Do you have insights on that?

@millenomi
Copy link
Contributor

Unfortunately, not as such.

@dduan
Copy link
Contributor Author

dduan commented Dec 21, 2017

@millenomi I've renamed all local variables in the method.

@dduan dduan force-pushed the fix-deletingPathExtension-inconsistency branch from c036da0 to 204f5d6 Compare December 21, 2017 01:07
@dduan dduan force-pushed the fix-deletingPathExtension-inconsistency branch from 204f5d6 to 32d542a Compare December 21, 2017 01:26
@dduan
Copy link
Contributor Author

dduan commented Dec 21, 2017

@swift-ci please test and merge

@swift-ci swift-ci merged commit 879e7f6 into swiftlang:master Dec 21, 2017
@dduan dduan deleted the fix-deletingPathExtension-inconsistency branch December 21, 2017 05:36
kylef pushed a commit to kylef/PathKit that referenced this pull request Dec 23, 2017
_Background_

A test for this API has been [failing, but only on macOS][0]. This is
due to a implementation difference between the closed-source Foundation
and its open-source counterpart. Recently, a [patch][1] has been made to
the latter to fix this issue. The patch is [included][2] in the upcoming
Swift 4.1 release.

_Changes_

Add a condition to the test so it passes on both platforms for now. The
expectation is that come Swift 4.1, this test will start failing on
Linux and the condition will be removed then.

[0]: https://travis-ci.org/kylef/PathKit/builds/289637066
[1]: swiftlang/swift-corelibs-foundation#1376
[2]: https://github.com/apple/swift-corelibs-foundation/commits/swift-4.1-branch
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants