mirror of
				https://github.com/jqlang/jq.git
				synced 2025-11-03 12:33:13 +03:00 
			
		
		
		
	contains should handle embedded NULs (fix #1732)
				
					
				
			This commit is contained in:
		
							
								
								
									
										3
									
								
								src/jv.c
									
									
									
									
									
								
							
							
						
						
									
										3
									
								
								src/jv.c
									
									
									
									
									
								
							@@ -1342,7 +1342,8 @@ int jv_contains(jv a, jv b) {
 | 
			
		||||
  } else if (jv_get_kind(a) == JV_KIND_ARRAY) {
 | 
			
		||||
    r = jv_array_contains(jv_copy(a), jv_copy(b));
 | 
			
		||||
  } else if (jv_get_kind(a) == JV_KIND_STRING) {
 | 
			
		||||
    r = strstr(jv_string_value(a), jv_string_value(b)) != 0;
 | 
			
		||||
    r = _jq_memmem(jv_string_value(a), jv_string_length_bytes(jv_copy(a)),
 | 
			
		||||
                   jv_string_value(b), jv_string_length_bytes(jv_copy(b))) != 0;
 | 
			
		||||
  } else {
 | 
			
		||||
    r = jv_equal(jv_copy(a), jv_copy(b));
 | 
			
		||||
  }
 | 
			
		||||
 
 | 
			
		||||
@@ -1091,6 +1091,11 @@ null
 | 
			
		||||
{}
 | 
			
		||||
[true, true, false]
 | 
			
		||||
 | 
			
		||||
# containment operator (embedded NULs!)
 | 
			
		||||
[contains("foo"), contains("\u0000b"), contains("\u0000z"),  contains("bar"), contains("baz")]
 | 
			
		||||
"foo\u0000bar"
 | 
			
		||||
[true, true, false, true, false]
 | 
			
		||||
 | 
			
		||||
# Try/catch and general `?` operator
 | 
			
		||||
[.[]|try if . == 0 then error("foo") elif . == 1 then .a elif . == 2 then empty else . end catch .]
 | 
			
		||||
[0,1,2,3]
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user