Skip to content

Commit f65d1f9

Browse files
committed
lua option '--' may not be followed by script
1 parent 942c10a commit f65d1f9

2 files changed

Lines changed: 7 additions & 5 deletions

File tree

lua.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -303,7 +303,8 @@ static int collectargs (char **argv, int *first) {
303303
case '-': /* '--' */
304304
if (argv[i][2] != '\0') /* extra characters after '--'? */
305305
return has_error; /* invalid option */
306-
*first = i + 1;
306+
/* if there is a script name, it comes after '--' */
307+
*first = (argv[i + 1] != NULL) ? i + 1 : 0;
307308
return args;
308309
case '\0': /* '-' */
309310
return args; /* script "name" is '-' */

testes/main.lua

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ prepfile[[
9090
1, a
9191
)
9292
]]
93-
RUN('lua - < %s > %s', prog, out)
93+
RUN('lua - -- < %s > %s', prog, out)
9494
checkout("1\tnil\n")
9595

9696
RUN('echo "print(10)\nprint(2)\n" | lua > %s', out)
@@ -133,7 +133,7 @@ checkout("-h\n")
133133
prepfile("print(package.path)")
134134

135135
-- test LUA_PATH
136-
RUN('env LUA_INIT= LUA_PATH=x lua %s > %s', prog, out)
136+
RUN('env LUA_INIT= LUA_PATH=x lua -- %s > %s', prog, out)
137137
checkout("x\n")
138138

139139
-- test LUA_PATH_version
@@ -358,7 +358,7 @@ RUN([[lua -e"_PROMPT='' _PROMPT2=''" -i < %s > %s]], prog, out)
358358
checkprogout("6\n10\n10\n\n")
359359

360360
prepfile("a = [[b\nc\nd\ne]]\na")
361-
RUN([[lua -e"_PROMPT='' _PROMPT2=''" -i < %s > %s]], prog, out)
361+
RUN([[lua -e"_PROMPT='' _PROMPT2=''" -i -- < %s > %s]], prog, out)
362362
checkprogout("b\nc\nd\ne\n\n")
363363

364364
-- input interrupted in continuation line
@@ -488,12 +488,13 @@ assert(not os.remove(out))
488488
-- invalid options
489489
NoRun("unrecognized option '-h'", "lua -h")
490490
NoRun("unrecognized option '---'", "lua ---")
491-
NoRun("unrecognized option '-Ex'", "lua -Ex")
491+
NoRun("unrecognized option '-Ex'", "lua -Ex --")
492492
NoRun("unrecognized option '-vv'", "lua -vv")
493493
NoRun("unrecognized option '-iv'", "lua -iv")
494494
NoRun("'-e' needs argument", "lua -e")
495495
NoRun("syntax error", "lua -e a")
496496
NoRun("'-l' needs argument", "lua -l")
497+
NoRun("-i", "lua -- -i") -- handles -i as a script name
497498

498499

499500
if T then -- test library?

0 commit comments

Comments
 (0)