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

Correctly handle paths containing whitespace character #248

Merged
merged 11 commits into from
Jan 24, 2024

Conversation

fzhinkin
Copy link
Collaborator

@fzhinkin fzhinkin commented Dec 8, 2023

Fixes #246

@fzhinkin fzhinkin marked this pull request as ready for review December 8, 2023 15:05
@fzhinkin fzhinkin linked an issue Dec 8, 2023 that may be closed by this pull request
@05nelsonm
Copy link

05nelsonm commented Dec 8, 2023

I was incorrect in terms of java.io.File parity. null should not be returned when encountering a parent return value of .

My own tests were not removing the trailing slashes when instantiating things.

./some_path should always return . for a parent

EDIT: So, the issue seems to be with Path not stripping trailing system separators from the end of the string when instantiating it for Native.

Java behavior:

println("'${File("path////")}'")
// 'path'

kotlinx-io behavior (Native):

println("'${Path("path////")}'")
// 'path////'

Need something like

private inline fun String.removeTrailingSlashes(): String {
    var l = length

    while (l > 0) {
        if (this[l - 1] == SystemPathSeparator) {
            l--
        } else {
            break
        }
    }

    return when (l) {
        0 -> ""
        length -> this
        else -> substring(0, l)
    }
}

@fzhinkin fzhinkin removed the request for review from shanshin December 11, 2023 15:39
@fzhinkin fzhinkin self-assigned this Dec 11, 2023
@fzhinkin fzhinkin changed the title Correctly handle paths containing whitespace character WIP: Correctly handle paths containing whitespace character Dec 14, 2023
@fzhinkin fzhinkin marked this pull request as draft December 14, 2023 14:04
@fzhinkin fzhinkin changed the title WIP: Correctly handle paths containing whitespace character Correctly handle paths containing whitespace character Jan 18, 2024
@fzhinkin fzhinkin marked this pull request as ready for review January 18, 2024 14:32
core/js/test/files/SmokeFileTestWindowsJS.kt Outdated Show resolved Hide resolved
core/common/src/files/Paths.kt Outdated Show resolved Hide resolved
core/js/src/files/PathsJs.kt Outdated Show resolved Hide resolved
core/mingw/src/files/FileSystemMingw.kt Outdated Show resolved Hide resolved
core/native/src/files/PathsNative.kt Show resolved Hide resolved
@fzhinkin fzhinkin merged commit 80a1cbc into develop Jan 24, 2024
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Path.parent for Native returns null for space-only parent directory
3 participants