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

Unexpected behaviour with null-characters in string using '\0' notation #1859

Open
RickardCardell opened this issue Feb 14, 2025 · 1 comment
Labels
bug Something isn't working

Comments

@RickardCardell
Copy link

RickardCardell commented Feb 14, 2025

Bug Report

Not sure what the reason is. It seems it handles the token after '\0' a bit odd. However, the '\x00 notation seems to work as expected.

1. Minimal reproduce step (Required)

    assert 'aa' == ("a" + "a")       # works
    assert '\0\0' == ("\0" + "\0")  # fails!

    assert '\0\0' == ("\0" + "0")  # doesn't fail!
    assert '\0A' == '\0' # doesn't fail!  Where did 'A' go?

2. What did you expect to see? (Required)

That each character with the '\0' notation is handled as a separate character. As in e.g. Python.
I.e. '\0\0' is two chars of the same code point.
'\0A' should be the same as "\0"+"A", which it isn't currently.

Python

> [ ord(c) for c in "\0\0"]
[0, 0]

KCL

> [ ord(c) for c in "\0\0"]
[0, 48]

3. What did you see instead (Required)

That '\0\0' equals to "\00".
"\0A" equals to "\0"

4. What is your KCL components version? (Required)

> kcl --version
kcl version 0.11.0

Same with 0.11.1

system:

> uname -a
Darwin 24.3.0 Darwin Kernel Version 24.3.0 ... arm64
@RickardCardell
Copy link
Author

Additional test cases to showcase the issue.
All these tests fails currently.

test_null0 = lambda {
    assert 'aa' == ("a" + "a") # Works as expected
    assert '\0\0' == ("\0" + "\0")
}

test_null1 = lambda {
    n = '\0\0'
    res = [ord(i) for i in n]
    assert res == [0, 0]
    # actual [0, 48]
}


test_null2 = lambda {
    n = '\0\0\0\0'
    res = [ord(i) for i in n]
    assert res == [0, 0, 0, 0]
    # actual [0, 48, 0, 48]
}

test_null3 = lambda {
    assert "\0A" != "\0"
}

test_null4 = lambda {
    n = 'A\0A'
    res = [ord(i) for i in n]
    assert res == [65, 0, 65]
    #actual [65, 0]
}

test_null5 = lambda {
    n = '\t\0\t'
    res = [ord(i) for i in n]
    assert res == [9, 0, 9]
    #actual [9, 0, 116]
}

@Peefy Peefy added the bug Something isn't working label Feb 14, 2025
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

2 participants