mirror of
https://github.com/ccxvii/mujs.git
synced 2026-02-05 17:29:43 +08:00
Issue 117: Skip first line if it starts with a shebang when loading files.
A file that starts with #! is going to be a syntax error anyway, so we won't be changing the behavior of any other valid source files with this fix.
This commit is contained in:
12
jsstate.c
12
jsstate.c
@@ -130,7 +130,7 @@ void js_loadstring(js_State *J, const char *filename, const char *source)
|
||||
void js_loadfile(js_State *J, const char *filename)
|
||||
{
|
||||
FILE *f;
|
||||
char *s;
|
||||
char *s, *p;
|
||||
int n, t;
|
||||
|
||||
f = fopen(filename, "rb");
|
||||
@@ -176,7 +176,15 @@ void js_loadfile(js_State *J, const char *filename)
|
||||
js_throw(J);
|
||||
}
|
||||
|
||||
js_loadstring(J, filename, s);
|
||||
/* skip first line if it starts with "#!" */
|
||||
p = s;
|
||||
if (p[0] == '#' && p[1] == '!') {
|
||||
p += 2;
|
||||
while (*p && *p != '\n')
|
||||
++p;
|
||||
}
|
||||
|
||||
js_loadstring(J, filename, p);
|
||||
|
||||
js_free(J, s);
|
||||
fclose(f);
|
||||
|
||||
Reference in New Issue
Block a user