name a project with special characters and try to donwload.
some of them will cause problem, e.g. &,|...
this is two things, right? 1. sketch names need a length limit (i don't know what an appropriate character limit is) and 2. sketch names need to be... url encoded? escaped somehow? not sure.
@shinytang6 Can you provide an example. I tried a couple of them including &, | and when downloading the sketch, & is named and, | - or .
@himanshuc3 What you listed is the problem:)
But what's the problem if the name of the file changes. It downloaded without any errors.
it doesn't matter with the content, should download the project in what you name.
@catarak Is anyone working on this issue? If not, then I'd like to take it up :) I plan to follow the advice given on this post for generating file names.
I plan to either:
Would you suggest anything else? I prefer the second option. I can also display a toast message every time a restricted character is trimmed out from a file name, so user would not be immediately surprised.
i suggest the latter. i don't think it makes sense to change the sketch titles as they are in the editor, other than giving them a length limit; rather, i think the sketch titles should be escaped only when they are downloaded and translated to the name of a zip file, as this is the only time the sketch title affects this.
So I was going through the codebase and noticed that the relevant method is this:
Note that it just opens a new window pointing to a resource that is probably already in the server. Where can I look at to edit the zip files file name?
The zip file is generated on the fly, so when a browser window requests that url, it generates the zip file. The entry point, server-side, is here: https://github.com/processing/p5.js-web-editor/blob/master/server/controllers/project.controller.js#L332
So, the problem here is that the first part of the file name (before the timestamp) is generated using slugify, which is too restrictive in what it allows. I noticed that even Chinese characters, which are perfectly valid in file names, are completely removed. Try 鏂囧瓧 as the sketch name for example.
I'll send in a PR.
there are TWO issues here, not just one:
Ok, I can work on the first one too. Two things:
server/ directory where the limit should be checked. Searching for project.name brings up files related to server/migration and other unrelated places. Where exactly to add this length validation?256 seems like it's a good starting point? maybe smaller than that makes sense?
On an average use case, I think names would be like Lab 25th January 2019 - Demonstrating recursive functions with colors that's about 60-70 characters. Thus, at max, even 128 chars seems more than enough for most cases. However, before setting out to impose a limit, I would first want to make sure what percentage of existing sketches would be impacted by this length limiting, and minimize the damage thereof.
let me do a query on the db...
UPDATE: there are 33 sketches with a name length greater than 128, and 15 with a name length greater than 256 (of 341,000 sketches). So, a very smaller number would be affected.
UPDATE2: because of these outlier name lengths, i can't create an index on the sketch names. so, that's another big reason to shorten the names.
Perfect, I'll try and get the length limit of 256 added into the code!
the OS issue was fixed, but adding a project name limit would also be good to add.
Will send a pr to close this
@siddhant1 I don't think a front-end check would cut it. You must also include a backend validation.
I'm going to try and tackle this.
Quick question, can we just use mongoose validators such as minlength and maxlength found here ? These will throw an error which can be caught and sent back to the client. (I haven't checked to see how validation errors are currently being handled.)
Also, by 'sketch name' are we referring to the project name or the file names, or both ?
@josephmwells using the validators makes sense to me! Also for this issue, it is referring to specifically the sketch title. It would be a separate issue/PR for the sketch files.