Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

A bug in the flag() builtin function #462

Open
s5unty opened this issue Dec 12, 2021 · 0 comments
Open

A bug in the flag() builtin function #462

s5unty opened this issue Dec 12, 2021 · 0 comments

Comments

@s5unty
Copy link
Contributor

s5unty commented Dec 12, 2021

#!/usr/bin/env abs

cli = require('@cli')

@cli.cmd("foo", "opts", {"s": 1 })
f foo(argv, flags) {
    echo("flags: %s", flags.str())
}

@cli.cmd("bar", "opts", {"ss":1 })
f bar(argv, flags) {
    echo("flags: %s", flags.str())
}

cli.run()
 % ./bug.abs foo -s
 flags: {"s": "./bug.abs"}
 % ./bug.abs bar -ss
 flags: {"ss": true}

When the flagFN() function iterates through os.Args,
the first v value is "abs", which causes the flag "s" to be misinterpreted.

diff --git evaluator/functions.go evaluator/functions.go
index 5d3d7c0..52999a7 100644
--- evaluator/functions.go
+++ evaluator/functions.go
@@ -615,7 +615,7 @@ func flagFn(tok token.Token, env *object.Environment, args ...object.Object) obj
        // passed to the script
        // This is O(n) but again, performance
        // is not a big deal in ABS
-       for _, v := range os.Args {
+       for _, v := range os.Args[1:] {
                // If the flag was found in the previous
                // argument...
                if found {
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant