Giter VIP home page Giter VIP logo

Comments (3)

alex65536 avatar alex65536 commented on July 22, 2024

While looking at the code, I have found out that there are two issues basically.

In joinPath(".", "a") and similar cases, the path becomes "." after first addNormalizePath and second addNormalizePath doesn't remove it. In test cases this one is called "controversial" because of how paths to executables behave on Unix systems:

Nim/tests/stdlib/tos.nim

Lines 590 to 594 in 0b5a938

# controversial: inconsistent with `joinPath("zook/.","abc")`
# on linux, `./foo` and `foo` are treated a bit differently for executables
# but not `./foo/bar` and `foo/bar`
doAssert joinPath(".", "/lib") == unixToNativePath"./lib"
doAssert joinPath(".", "abc") == unixToNativePath"./abc"

Retaining this behavior might be good to prevent older programs from breaking, but it starts to look much weirder in case of joinPath("b", "..", "a") or joinPath(".", ".."), so probably worth either fixing or documenting.

The second part is less controversial and more looks like a bug. The problem is in the line

it.notFirst = (state shr 1) > 0

This is not the correct way to check if it's the first component of the path, as state == 0 holds also for such paths as . or ../... Thus, when handling joinPath("x/..", "/a", "/b", "../../..") it starts to think at some point that the path is absolute, because it receives "/" from PathIter. Though, by coincidence and only because the . is not removed because of the first issue, it seems that such incorrect state doesn't lead to wrong results (or at least I haven't been able to found the failing case).

from nim.

juancarlospaco avatar juancarlospaco commented on July 22, 2024

But ./a is not the same as a. 🤔

from nim.

alex65536 avatar alex65536 commented on July 22, 2024

But ./a is not the same as a. 🤔

Well, but

import std/[os, paths]

echo normalizedPath("./a")
echo "./a".Path == "a".Path

prints

a
true

And the documentation promises that joinPath

## returns normalized path concatenation of `head` and `tail`, preserving
## whether or not `tail` has a trailing slash (or, if tail if empty, whether
## head has one).

but ./a is obviously not normalized.

from nim.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.