arturo-lang / arturo

Simple, expressive & portable programming language for efficient scripting
http://arturo-lang.io
MIT License
700 stars 32 forks source link

[Collections/split] Is `.path` working correctly? #872

Closed github-actions[bot] closed 1 year ago

github-actions[bot] commented 1 year ago

[Collections/split] Is .path working correctly?

example: debug split.path "directory/wofilerld"

This should return an array containing directory and wofilerld, which exactly how it works for me (on macOS), but there could be issues with other OSes?

https://github.com/arturo-lang/arturo/blob/1136d74ff6685ec5b16c64021b3cf1a0dfc45fa8/src/library/Collections.nim#L1704

    #  labels: library,bug

    # TODO(Collections/split) `.by` not working properly with Literal values?
    #  example: ```
    #   b: ["Arnold" "Andreas" "Paul" "Ricard" "Linus" "Yanis" "Helena" "Eva" "Blanca"]
    #   split.every: 3 'b, debug b
    #  ```
    #  labels: library, bug

    # TODO(Collections/split) Is `.path` working correctly?
    #  example: `debug split.path "directory/wofilerld"`
    #  This should return an array containing `directory` and `wofilerld`, which exactly how it works for me (on macOS), but there could be issues with other OSes?
    #  labels: library, bug, open discussion
    builtin "split",
        alias       = unaliased,
        rule        = PrefixPrecedence,
ndex b0082f6be..f7fbd3cec 100644
++ b/tests/unittests/lib.collections.art

387a336a63f3eb63994641cb3d81b8953e459d68

RickBarretto commented 1 year ago

Alright, this is what is happening on Windows OS:

As you may know, Windows uses \ to separate directories and Unix uses /. So, what is happening here:

split.path issue Yep, it's mixing \ with /. So, I think it may be the current error.

RickBarretto commented 1 year ago

More detailed what is happening here. (The problem isn't on this library itself), look:

I created a file called paths.art with this code: image

Look what happens when I run it:

image

So, look at lines 1750 and 1797. Arturo is using the function item.split(DirSep)), split is a nim's standard function from strutils.nim module, none problem here, and DirSep that also is a nim's standard function comes from osseps.nim module, none problem here too.

But, let's see what DirSep returns for windows systems:

  DirSep* =
    when defined(macos): ':'
    elif doslikeFileSystem or defined(vxworks): '\\'
    elif defined(RISCOS): '.'
    else: '/'
    ## The character used by the operating system to separate pathname
    ## components, for example: `'/'` for POSIX, `':'` for the classic
    ## Macintosh, and `'\\'` on Windows.

Yes, it'll split using a \. As Arturo's module function is returning with bot separators, it won't work. It'll separate just until user's path, and then a big string.

It's a issue related with module function.

RickBarretto commented 1 year ago

Also, I must say. At the same ossep.nim module, exists an AltSep for windows systems:

  AltSep* =
    when doslikeFileSystem: '/'
    else: DirSep
    ## An alternative character used by the operating system to separate
    ## pathname components, or the same as `DirSep <#DirSep>`_ if only one separator
    ## character exists. This is set to `'/'` on Windows systems
    ## where `DirSep <#DirSep>`_ is a backslash (`'\\'`).
drkameleon commented 1 year ago

Fixed in https://github.com/arturo-lang/arturo/pull/880