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

Unquoted String Envvar is Incorrectly Parsed as Integer #5186

Open
kupmanyu opened this issue Mar 7, 2024 · 1 comment
Open

Unquoted String Envvar is Incorrectly Parsed as Integer #5186

kupmanyu opened this issue Mar 7, 2024 · 1 comment
Assignees
Labels
defect Suspected defect such as a bug or regression

Comments

@kupmanyu
Copy link

kupmanyu commented Mar 7, 2024

Observed behavior

An unquoted String envvar that matches the regex [0-9]+[kKmMgGtTpPeE][0-9].* (e.g. "0K1abc" or "8m4dwr") is incorrectly parsed as an integer and not as a string.

The below error is present in the logs:

nats-server: variable reference for 'TEST_KEY' on line 10 could not be parsed: Parse error on line 1: 'Expected a top-level value to end with a new line, comment or EOF, but got '4' instead.'

Related to #3431 and its fix in #3434 and #3436.

The issue is probably related to the unicode.isDigit(r) check in the lexConvenientNumber function here

Expected behavior

String envvar is parsed as a string.

Server and client version

Tested on both 2.9.16-scratch and latest

Host environment

No response

Steps to reproduce

Here is a unit test that shows this issue. It can be part of the TestConvenientIntegerValues test in conf/lex_test.go.

expectedItems := []item{
	{itemKey, "foo", 1, 0},
	{itemString, "0K1abc", 1, 6},
	{itemEOF, "", 1, 0},
}
lx := lex("foo = 0K1abc")
expect(t, lx, expectedItems)

Expected result:

Test case passes

Actual Result:

Test case fails with error:

Testing: 'foo = 0K1abc'
        Expected "(String, '0K1abc', 1, 6)", received "(Integer, '0K', 1, 6)"
@kupmanyu kupmanyu added the defect Suspected defect such as a bug or regression label Mar 7, 2024
@kupmanyu
Copy link
Author

kupmanyu commented Mar 8, 2024

The regex [0-9][kKmMgGtTpPeE][0-9].* should actually be [0-9]+[kKmMgGtTpPeE][0-9].* since the string "80m3hfe" also raises an error. I will update the issue with the correct regex.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
defect Suspected defect such as a bug or regression
Projects
None yet
Development

No branches or pull requests

3 participants