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

Embedded null bytes in source files #12279

Open
HertzDevil opened this issue Jul 16, 2022 · 1 comment
Open

Embedded null bytes in source files #12279

HertzDevil opened this issue Jul 16, 2022 · 1 comment

Comments

@HertzDevil
Copy link
Contributor

Crystal::Lexer uses '\0' to check for end-of-file conditions in multiple places, instead of Char::Reader#has_next?. A source file that contains a null byte will most likely fail to compile, e.g. when it appears within a string literal:

$ xxd test.cr
00000000: 7020 2261 0062 220a                      p "a.b".
$ crystal test.cr
In test.cr:1:5

 1 | p "ab"
         ^
Error: Unterminated string literal

Ruby seems to happily accept this:

$ ruby test.cr
"a\u0000b"

Should we allow those null bytes?

@asterite
Copy link
Member

I think back then I checked against the null byte just because I didn't think of a use case for having null bytes. But I don't see anything wrong with allowing that either, for completeness.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants