ref: c695b53a759cb7209e4b15abaec365fa0049bdc4
parent: 457f87b17bbf6e1654073c870a49e9f02ae63143
author: Tor Andersson <tor.andersson@artifex.com>
date: Thu Jan 2 09:30:43 EST 2020
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.
--- a/jsstate.c
+++ b/jsstate.c
@@ -130,7 +130,7 @@
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 @@
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);