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

Fix infinite loop on Windows caused by checking path against "/". #802

Merged
merged 2 commits into from
Sep 6, 2024

Conversation

shawnhyam
Copy link
Contributor

Should fix #694.

Copy link
Member

@allevato allevato left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't know what a root-only file: URL like C:/ on Windows looks like and I don't have a good way to test it. @compnerd does this look reasonable to you?

@compnerd
Copy link
Member

compnerd commented Sep 4, 2024

I think that it depends on what you are using. Particularly with swift-foundation, it should be /[A-Z]:/, unless you do the correct thing and use withFileSystemRepresentation, in which case it would be [A-Z]:\.

@@ -415,7 +415,7 @@ public struct Configuration: Codable, Equatable {
if FileManager.default.isReadableFile(atPath: candidateFile.path) {
return candidateFile
}
} while candidateDirectory.path != "/"
} while candidateDirectory.pathComponents.count > 1
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The concern that I have with this on Windows is that this would return true for C: and \, both of which are relative paths.

Copy link
Member

@compnerd compnerd left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems generic enough to work. It is unfortunate that Foundation doesn't have a isRoot property.

@allevato allevato merged commit a1ee216 into swiftlang:main Sep 6, 2024
ahoppen added a commit to ahoppen/swift-format that referenced this pull request Oct 10, 2024
…'t contain a `.swift-format` file

swiftlang#802 this sort of infinite looping issue on Windows but introduced it on Unix platforms where `URL.deletingLastPathComponent` on `/` returns `/..`.
ahoppen added a commit to ahoppen/swift-format that referenced this pull request Oct 10, 2024
…'t contain a `.swift-format` file

swiftlang#802 this sort of infinite looping issue on Windows but introduced it on Unix platforms where `URL.deletingLastPathComponent` on `/` returns `/..`.
ahoppen added a commit to ahoppen/swift-format that referenced this pull request Oct 11, 2024
…'t contain a `.swift-format` file

swiftlang#802 this sort of infinite looping issue on Windows but introduced it on Unix platforms where `URL.deletingLastPathComponent` on `/` returns `/..`.

# Conflicts:
#	Sources/SwiftFormat/API/Configuration.swift
ahoppen added a commit to ahoppen/swift-format that referenced this pull request Oct 11, 2024
…'t contain a `.swift-format` file

swiftlang#802 this sort of infinite looping issue on Windows but introduced it on Unix platforms where `URL.deletingLastPathComponent` on `/` returns `/..`.
ahoppen added a commit to ahoppen/swift-format that referenced this pull request Oct 11, 2024
…'t contain a `.swift-format` file

swiftlang#802 this sort of infinite looping issue on Windows but introduced it on Unix platforms where `URL.deletingLastPathComponent` on `/` returns `/..`.
ahoppen added a commit to ahoppen/swift-format that referenced this pull request Oct 11, 2024
…'t contain a `.swift-format` file

swiftlang#802 this sort of infinite looping issue on Windows but introduced it on Unix platforms where `URL.deletingLastPathComponent` on `/` returns `/..`.
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.

Formatting not working on Windows
3 participants