Skip to content

Provide guarantees about portable path ordering #130

Description

@ForNeVeR

In other ecosystems (e.g. Java), I was once surprised by the following behavior.

Say you have a list of relative paths (legally distinguishable on multiple operating systems, i.e. they don't have case conflicts and mix-ups), and you sort them.

In Java, there's no guarantee you'll have the same order on all operating systems, because / and \ have different sort order, and even if you have the same path letters, you'll have different order — say, items ["a/a", "a-a", "a.a"] vs ["a-a", "a.a", @"a\a"] might be sorted differently.

A particular problem I've had with this:

> listOf(
  java.nio.file.Path.of("commons"),
  java.nio.file.Path.of("com/x")
).sortedBy { it }
// => [commons, com\x]

> listOf(
  "commons",
  "com/x"
).sortedBy { it }
// => [com/x, commons]

TruePath should guarantee the same ordering for items involving directory separators (i.e. the directory separator should have the same ordering on all the operating systems), document this and cover by tests, of course.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions