Skip to content

Conversation

fzhinkin
Copy link
Collaborator

@fzhinkin fzhinkin commented Dec 8, 2023

Fixes #246

@fzhinkin fzhinkin requested a review from shanshin December 8, 2023 15:05
@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 requested a review from shanshin January 18, 2024 14:31
@fzhinkin fzhinkin marked this pull request as ready for review January 18, 2024 14:32
@fzhinkin fzhinkin requested a review from shanshin January 23, 2024 08:23
@fzhinkin fzhinkin merged commit 80a1cbc into develop Jan 24, 2024
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