mirror of
				https://github.com/neovim/neovim.git
				synced 2025-11-04 09:44:31 +00:00 
			
		
		
		
	fix(vim.json): loss of precision on integers >14 digits #34876
Problem: multiple DAP servers keep assuming they can have internal IDs
         up to 2**52, which get corrupted by the Neovim JSON encoder.
Solution: change (1) constant and add a test so nobody breaks it while
          updating the library.
Fixes: https://github.com/neovim/neovim/issues/24532
Fixes: https://github.com/mfussenegger/nvim-dap/issues/1534
Fixes: https://github.com/facebook/buck2/issues/1032
(cherry picked from commit 7a69fefdb9)
			
			
This commit is contained in:
		
				
					committed by
					
						
						github-actions[bot]
					
				
			
			
				
	
			
			
			
						parent
						
							6f8efea940
						
					
				
				
					commit
					f9f0345eba
				
			
							
								
								
									
										2
									
								
								src/cjson/lua_cjson.c
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										2
									
								
								src/cjson/lua_cjson.c
									
									
									
									
										vendored
									
									
								
							@@ -82,7 +82,7 @@
 | 
				
			|||||||
#define DEFAULT_ENCODE_INVALID_NUMBERS 0
 | 
					#define DEFAULT_ENCODE_INVALID_NUMBERS 0
 | 
				
			||||||
#define DEFAULT_DECODE_INVALID_NUMBERS 1
 | 
					#define DEFAULT_DECODE_INVALID_NUMBERS 1
 | 
				
			||||||
#define DEFAULT_ENCODE_KEEP_BUFFER 1
 | 
					#define DEFAULT_ENCODE_KEEP_BUFFER 1
 | 
				
			||||||
#define DEFAULT_ENCODE_NUMBER_PRECISION 14
 | 
					#define DEFAULT_ENCODE_NUMBER_PRECISION 16
 | 
				
			||||||
#define DEFAULT_ENCODE_EMPTY_TABLE_AS_OBJECT 0
 | 
					#define DEFAULT_ENCODE_EMPTY_TABLE_AS_OBJECT 0
 | 
				
			||||||
#define DEFAULT_DECODE_ARRAY_WITH_ARRAY_MT 0
 | 
					#define DEFAULT_DECODE_ARRAY_WITH_ARRAY_MT 0
 | 
				
			||||||
#define DEFAULT_ENCODE_ESCAPE_FORWARD_SLASH 1
 | 
					#define DEFAULT_ENCODE_ESCAPE_FORWARD_SLASH 1
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -77,6 +77,7 @@ describe('vim.json.decode()', function()
 | 
				
			|||||||
    eq(-100000, exec_lua([[return vim.json.decode('  -100000  ')]]))
 | 
					    eq(-100000, exec_lua([[return vim.json.decode('  -100000  ')]]))
 | 
				
			||||||
    eq(0, exec_lua([[return vim.json.decode('0')]]))
 | 
					    eq(0, exec_lua([[return vim.json.decode('0')]]))
 | 
				
			||||||
    eq(0, exec_lua([[return vim.json.decode('-0')]]))
 | 
					    eq(0, exec_lua([[return vim.json.decode('-0')]]))
 | 
				
			||||||
 | 
					    eq(3053700806959403, exec_lua([[return vim.json.decode('3053700806959403')]]))
 | 
				
			||||||
  end)
 | 
					  end)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  it('parses floating-point numbers', function()
 | 
					  it('parses floating-point numbers', function()
 | 
				
			||||||
@@ -208,6 +209,7 @@ describe('vim.json.encode()', function()
 | 
				
			|||||||
  end)
 | 
					  end)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  it('dumps floats', function()
 | 
					  it('dumps floats', function()
 | 
				
			||||||
 | 
					    eq('3053700806959403', exec_lua([[return vim.json.encode(3053700806959403)]]))
 | 
				
			||||||
    eq('10.5', exec_lua([[return vim.json.encode(10.5)]]))
 | 
					    eq('10.5', exec_lua([[return vim.json.encode(10.5)]]))
 | 
				
			||||||
    eq('-10.5', exec_lua([[return vim.json.encode(-10.5)]]))
 | 
					    eq('-10.5', exec_lua([[return vim.json.encode(-10.5)]]))
 | 
				
			||||||
    eq('-1e-05', exec_lua([[return vim.json.encode(-1e-5)]]))
 | 
					    eq('-1e-05', exec_lua([[return vim.json.encode(-1e-5)]]))
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user