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

json2.raw_decode/1 fails to parse valid json content, that has escaped characters in it #23884

Open
spytheman opened this issue Mar 8, 2025 · 5 comments
Labels
Bug This tag is applied to issues which reports bugs. Modules: x.json2 Bugs related to *only* x.json2 (the pure V implementation) Unit: vlib Bugs/feature requests, that are related to the vlib.

Comments

@spytheman
Copy link
Member

spytheman commented Mar 8, 2025

V version: V 0.4.9 4236baf, press to see full `v doctor` output
V full version V 0.4.9 bc3fc12.4236baf
OS linux, Ubuntu 20.04.6 LTS
Processor 4 cpus, 64bit, little endian, Intel(R) Core(TM) i3-3225 CPU @ 3.30GHz
Memory 0.52GB/15.05GB
V executable /home/delian/code/v/v
V last modified time 2025-03-08 08:06:24
V home dir OK, value: /home/delian/code/v
VMODULES OK, value: /home/delian/.vmodules
VTMP OK, value: /tmp/v_1000
Current working dir OK, value: /home/delian/code/v
env VFLAGS "-no-parallel"
Git version git version 2.48.1
V git status weekly.2025.10-38-gaf624713-dirty
.git/config present true
cc version cc (Ubuntu 10.5.0-1ubuntu1~20.04) 10.5.0
gcc version gcc (Ubuntu 10.5.0-1ubuntu1~20.04) 10.5.0
clang version clang version 10.0.0-4ubuntu1
tcc version tcc version 0.9.28rc 2024-07-31 HEAD@1cee0908 (x86_64 Linux)
tcc git status thirdparty-linux-amd64 0134e9b9
emcc version N/A
glibc version ldd (Ubuntu GLIBC 2.31-0ubuntu9.16) 2.31

What did you do?
./v -g -o vdbg cmd/v && ./vdbg x.v && x

import x.json2

content := r'{"some_name": "some_value \n [ ] { } ( ) , ; ? * = ! \\@ \\"}'
d := json2.raw_decode(content)!
dump(d)

What did you see?

================ V panic ================
   module: main
 function: main()
  message: [x.json2] missing double quotes in string closing (0:98)
     file: x.v:4
   v hash: 4236baf
=========================================
/tmp/v_1000/../../../../../../home/delian/code/v/vlib/builtin/builtin.c.v:88: at panic_debug: Backtrace
/tmp/v_1000/../../../../../../home/delian/code/v/x.v:6: by main__main

What did you expect to see?

The value of d should be printed, the json2.raw_decode/1 should not return an error for valid json content.

Note

You can use the 👍 reaction to increase the issue's priority for developers.

Please note that only the 👍 reaction to the issue itself counts as a vote.
Other reactions and those to comments will not be taken into account.

@spytheman spytheman added Bug This tag is applied to issues which reports bugs. Modules: x.json2 Bugs related to *only* x.json2 (the pure V implementation) Unit: vlib Bugs/feature requests, that are related to the vlib. labels Mar 8, 2025
Copy link

Connected to Huly®: V_0.6-22287

@spytheman
Copy link
Member Author

From Discord, from @revosw :

Strange, the entire string looks like this:

"**SQLValidDSN** is called by a driver's [ConfigDSN](../../../odbc/reference/syntax/configdsn-function.md) to check the length of the data source name and the validity of the individual characters in the data source name. It checks whether the length of the name is greater than SQL_MAX_DSN_LENGTH, as defined in Sqlext.h. (The length of the data source name is also checked by [SQLWriteDSNToIni](../../../odbc/reference/syntax/sqlwritedsntoini-function.md).) **SQLValidDSN** checks whether any of the following invalid characters are included in the data source name:  \n  \n [ ] { } ( ) , ; ? * = ! \\@ \\"

@spytheman
Copy link
Member Author

Note: jq has no problems parsing that content:

Image

It also passes validation with https://jsonlint.com/ .

@changrui
Copy link
Contributor

changrui commented Mar 9, 2025

Module json is running well and decode to a struct or map[string]string correctly.

@spytheman
Copy link
Member Author

Yes, the issue is specific to the x.json2 decoder.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug This tag is applied to issues which reports bugs. Modules: x.json2 Bugs related to *only* x.json2 (the pure V implementation) Unit: vlib Bugs/feature requests, that are related to the vlib.
Projects
None yet
Development

No branches or pull requests

2 participants