was trying to investigate https://github.com/citycide/glob/issues/15 (I can't reproduce this on Windows.)
Turns out it's because nim 0.18.0 and nim 0.18.1 handle empty and nil strings differently, and nim 0.18.1 correctly throws on out of bound errors.
The issue is that ospaths.isAbsolute doesn't check for out of bound errors in the code: result = path[0] == '/'
isAbsolute return false (as in dlang std.process.isAbsolute) on nil/empty string or throw? either way, should be documented. My feeling is that throwing sounds saner. test.nim:
proc test2()=
try:
var a = ""
echo ("a[0]",a[0])
except Exception as e: echo e[]
try:
var a2: string = nil
echo ("a2[0]",a2[0])
except Exception as e: echo e[]
nim 0.18.0:
(Field0: "a[0]", Field1: '\x00')
Traceback (most recent call last)
/private/tmp/d06/t49_glob_fail2.nim(43) t49_glob_fail2
/private/tmp/d06/t49_glob_fail2.nim(12) test2
SIGSEGV: Illegal storage access. (Attempt to read from nil?)
nim 0.18.1:
(parent: ...name: IndexError, msg: "index out of bounds", trace: /private/tmp/d06/t49_glob_fail2.nim(43) t49_glob_fail2
/private/tmp/d06/t49_glob_fail2.nim(7) test2
/Users/timothee/.choosenim/toolchains/nim-#devel/lib/system.nim(2871) sysFatal
, raise_id: 0, up: ...)
(parent: ...name: IndexError, msg: "index out of bounds", trace: /private/tmp/d06/t49_glob_fail2.nim(43) t49_glob_fail2
/private/tmp/d06/t49_glob_fail2.nim(12) test2
/Users/timothee/.choosenim/toolchains/nim-#devel/lib/system.nim(2871) sysFatal
, raise_id: 0, up: ...)
=> good, 0.18.1 throws out of bound errors.
I don't think it should throw. Equivalent functions in Rust, D, Python, & Node all just return false when given an empty string.
PR merged, closing this
I don't think it should throw. Equivalent functions in Rust, D, Python, & Node all just return false when given an empty string.
ok, the PR follows that suggestion
Most helpful comment
I don't think it should throw. Equivalent functions in Rust, D, Python, & Node all just return
falsewhen given an empty string.