commit cf8f027
Merge pull request 'static files: allow files in a subdirectory' (#541) from lbr/snac2:master into master Reviewed-on: https://codeberg.org/grunfink/snac2/pulls/541
M
data.c
+9,
-6
1@@ -2673,14 +2673,17 @@ static int _load_raw_file(const char *fn, xs_val **data, int *size,
2 }
3 else {
4 /* newer or never downloaded; read the full file */
5+ struct stat sb;
6 FILE *f;
7
8- if ((f = fopen(fn, "rb")) != NULL) {
9- *size = XS_ALL;
10- *data = xs_read(f, size);
11- fclose(f);
12+ if (lstat(fn, &sb) == 0 && (sb.st_mode&S_IFMT) == S_IFREG) {
13+ if ((f = fopen(fn, "rb")) != NULL) {
14+ *size = XS_ALL;
15+ *data = xs_read(f, size);
16+ fclose(f);
17
18- status = HTTP_STATUS_OK;
19+ status = HTTP_STATUS_OK;
20+ }
21 }
22 }
23
24@@ -2699,7 +2702,7 @@ static int _load_raw_file(const char *fn, xs_val **data, int *size,
25 xs_str *_static_fn(snac *snac, const char *id)
26 /* gets the filename for a static file */
27 {
28- if (strchr(id, '/'))
29+ if (strstr(id, ".."))
30 return NULL;
31 else
32 return xs_fmt("%s/static/%s", snac->basedir, id);
M
html.c
+1,
-1
1@@ -5073,7 +5073,7 @@ int html_get_handler(const xs_dict *req, const char *q_path,
2 }
3 else
4 if (xs_startswith(p_path, "s/")) { /** a static file **/
5- xs *l = xs_split(p_path, "/");
6+ xs *l = xs_split_n(p_path, "/", 1);
7 const char *id = xs_list_get(l, 1);
8 int sz;
9