Page 2 of 2

Re: File wont save

Posted: Sat Jun 17, 2023 7:52 pm
by Andlac028
zalander wrote: Sat Jun 17, 2023 5:28 pm
Andlac028 wrote: Sat Jun 17, 2023 2:19 pm
zalander wrote: Sat Jun 17, 2023 4:32 am I added this to the love.update function and it tells me that the file name is illegal or is insecure

Code: Select all

	if love.keyboard.isDown("return") then
            local success, message = love.filesystem.write(game.file_n, game.txt)
            if success then
                print("File saved successfully!")
            else
                print("Error saving file:", message)
            end
        end
And what is the filename?
The file name can differ as the user enters it.
Ok, tell me, what is the filename and content when error is thrown (eg add print with all parameters as in love.filesystem.write to print with error)

Re: File wont save

Posted: Sun Jun 18, 2023 12:39 am
by yal2du
The file name can differ as the user enters it.
https://love2d.org/wiki/love.filesystem

prob need to sanitize the user input. love.filesystem.write will only write to specific directories (detailed in docs above) and it sounds like the path being specified isn't one of them.

Re: File wont save

Posted: Sun Jun 18, 2023 4:09 am
by zorg
It should only be a filename, and not a full path though; otherwise most characters should be accepted as names anyway.

Re: File wont save

Posted: Sun Jun 18, 2023 8:33 am
by zalander
zorg wrote: Sun Jun 18, 2023 4:09 am It should only be a filename, and not a full path though; otherwise most characters should be accepted as names anyway.
its just the file name not the full path

Re: File wont save

Posted: Sun Jun 18, 2023 8:35 am
by zalander
ohhh i got it my code adds a "\b" that needs to be removed before saving the file thanks for the help guys !
:awesome:

Re: File wont save

Posted: Sun Jun 18, 2023 10:54 am
by zorg
You're welcome, although for future reference, playing one question - one partial answer might not be the best of ideas; i believe that if you posted all relevant code we might have solved this in just one post.