Skip to content

Path.parent for Native returns null for space-only parent directory #246

@05nelsonm

Description

@05nelsonm

Path.parent utilizes isBlank() when checking returned value from dirname. This is incorrect, as a parent directory can be created as just a space.

# shell
mkdir " "

The following assertion should pass:

assertEquals(" ", Path(" /.").parent?.toString() ?: "NULL")

Which is the same behavior as Jvm's java.io.File

If java.io.File behavior (the underlying on Jvm) is desired to be mimicked for Native, the dirname check should be:

val parentName = dirnameImpl(path)

return when {
    parentName.isEmpty() -> null
    parentName == "." -> null
    parentName == path -> null
    else -> parentName
}

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions