Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fileRead bug #3297

Closed
1 task done
FileEX opened this issue Jan 22, 2024 · 3 comments
Closed
1 task done

fileRead bug #3297

FileEX opened this issue Jan 22, 2024 · 3 comments
Labels
bug Something isn't working

Comments

@FileEX
Copy link
Contributor

FileEX commented Jan 22, 2024

Describe the bug

When we read a file via fileRead, for some reason it is not read correctly (maybe empty lines are being removed?) - I know that it worked correctly half a year ago.

[Title]
Some title

[Body]
Some text

[Date]
22.01.2024

Lua code

	        local file = fileOpen('file.txt', true);
	        local data = fileRead(file, fileGetSize(file));

	        local title = string.match(data, '%[Title%]\n(.+)\n\n%[Body%]'); -- nil
	        local content = string.match(data, '%[Body%]\n(.+)\n\n%[Date%]'); -- nil
	        local date = string.match(data, '%[Date%]\n(.+)\n'); -- nil

	        print(title,content,date)

Why do I say it's a file reading problem? Because if we insert the same text as a string, everything will be read correctly

	        local data = [[[Title]
Some title

[Body]
Some text

[Date]
22.01.2024
]]

	        local title = string.match(data, '%[Title%]\n(.+)\n\n%[Body%]'); -- Some title
	        local content = string.match(data, '%[Body%]\n(.+)\n\n%[Date%]'); -- Some text
	        local date = string.match(data, '%[Date%]\n(.+)\n'); -- 22.01.2024

	        print(title,content,date)

Steps to reproduce

Described in the explanation

Version

Multi Theft Auto v1.6-release-22364

Additional context

No response

Relevant log output

No response

Security Policy

  • I have read and understood the Security Policy and this issue is not security related.
@FileEX FileEX added the bug Something isn't working label Jan 22, 2024
@TracerDS
Copy link
Contributor

TracerDS commented Jan 22, 2024

On Windows line ends with \r\n.
On Unix line ends with \n

Did you also try to print the data itself?

@FileEX
Copy link
Contributor Author

FileEX commented Jan 22, 2024

Indeed, changing \n to \r\n helped. I'm just wondering how it worked before (I used old code I wrote once and it worked)

@FileEX FileEX closed this as completed Jan 23, 2024
@Pirulax
Copy link
Contributor

Pirulax commented Jan 23, 2024

We open the files in binary mode, thus you get no character normalization.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants