Seedmanc / Booru-mass-uploader

This userscript allows you to mass-upload images to imageboard sites running *booru engines.
MIT License
34 stars 12 forks source link

Filenames with spaces are truncated to the last word dot extension #33

Open duanemoody opened 3 years ago

duanemoody commented 3 years ago

If you've checkmarked Set Title of each image to its original filename, this is a picture.gif becomes picture.gif in the title field. I suspect this regex in uploader.js is to blame: tags = fileName; title = upOptions.title ? tags.split(/\s+/)[tags.split(/\s+/).length - 1] : ''; It's assuming "last space is delimiter to filename inside fileName" which only works if the filename has no spaces in it. If I've read the source correctly, fileName is actually "[rating] [tags] [filename]" where an array would be safer to parse: fileInfo['rating'], fileInfo['tags'], fileInfo['filename']

Seedmanc commented 3 years ago

Yes, but how would we separate filename from tags if it has spaces as well?

duanemoody commented 3 years ago

Two choices:

  1. bandaid: Use a nonprinting delimiter character that's illegal in most file systems like ESC
  2. better practices: Stop using string packing as a way to attack this problam and pass myArray = [rating,tags] using formData.append('myArray',myArray[])
Seedmanc commented 3 years ago

Not quite sure what you mean by (2), doesn't the problem lie in file naming, it would be too late to fix it at the uploading stage? It's either stating clearly in the Readme that the files shouldn't have spaces in their name part, or using a special character or multiple spaces to delimit tags from the actual name.

I would opt for an easier solution, since I'm no longer actively developing this project and the last thing I want to do is to break something.