summaryrefslogtreecommitdiff
path: root/src/process_url.c
diff options
context:
space:
mode:
authorMole Shang <[email protected]>2023-08-06 18:45:37 +0800
committerMole Shang <[email protected]>2023-08-06 18:45:37 +0800
commitbde03538d66c37d5690ab321173eb83ecfcaf2ff (patch)
treeae7bc81f0ca5ff8562afa61bbd7d0af94195b25a /src/process_url.c
parentc21d660c0932c45bde08a92ffa2686fd472b1b9e (diff)
downloadhinata-bde03538d66c37d5690ab321173eb83ecfcaf2ff.tar.gz
hinata-bde03538d66c37d5690ab321173eb83ecfcaf2ff.tar.bz2
hinata-bde03538d66c37d5690ab321173eb83ecfcaf2ff.zip
process_url: strip illegal characters in filename
There are edge cases when a retrived title contains illegal characters (e.g. '/'). Replace it with a space to ensure a valid filename. Reproducible case: https://www.bilibili.com/video/av20827366/ (title="【2K/60fps】这可能是我做过最美的miku了【boomclap布料解算版】")
Diffstat (limited to 'src/process_url.c')
-rw-r--r--src/process_url.c8
1 files changed, 8 insertions, 0 deletions
diff --git a/src/process_url.c b/src/process_url.c
index 4bfce8d..7a92013 100644
--- a/src/process_url.c
+++ b/src/process_url.c
@@ -29,6 +29,9 @@ extern Site_map site_map;
Options options;
static queue_t dl_queue;
+const char illegal_char[] = {'/', '\\', '|', '<', '>',
+ ':', '"', '?', '*', '\0'};
+
thrd_t tid[MAX_THREAD];
mtx_t mtx;
cnd_t cnd;
@@ -516,6 +519,11 @@ void add_url(const char *URL, const char *outdir, const char *fn,
} else {
filename = malloc(strlen(fn) + 1);
strcpy(filename, fn);
+ for (unsigned char i = 0; illegal_char[i] != '\0'; i++) {
+ if (repchr(filename, illegal_char[i], ' '))
+ DEBUG_PRINT("Found illegal character '%c' in filename, replacing ...\n",
+ illegal_char[i]);
+ }
}
// Pass our cache (outdir_g) to parse_url()