mirror of
				https://github.com/spring-projects/spring-data-elasticsearch.git
				synced 2025-10-31 14:48:56 +00:00 
			
		
		
		
	
							parent
							
								
									c05146adce
								
							
						
					
					
						commit
						03ecc48b09
					
				| @ -46,7 +46,11 @@ final public class StringQueryUtil { | |||||||
| 
 | 
 | ||||||
| 			String placeholder = Pattern.quote(matcher.group()) + "(?!\\d+)"; | 			String placeholder = Pattern.quote(matcher.group()) + "(?!\\d+)"; | ||||||
| 			int index = NumberUtils.parseNumber(matcher.group(1), Integer.class); | 			int index = NumberUtils.parseNumber(matcher.group(1), Integer.class); | ||||||
| 			result = result.replaceAll(placeholder, Matcher.quoteReplacement(getParameterWithIndex(accessor, index))); | 			String replacement = Matcher.quoteReplacement(getParameterWithIndex(accessor, index)); | ||||||
|  | 			result = result.replaceAll(placeholder, replacement); | ||||||
|  | 			// need to escape backslashes that are not escapes for quotes so that they are sent as double-backslashes | ||||||
|  | 			// to Elasticsearch | ||||||
|  | 			result = result.replaceAll("\\\\([^\"'])", "\\\\\\\\$1"); | ||||||
| 		} | 		} | ||||||
| 		return result; | 		return result; | ||||||
| 	} | 	} | ||||||
| @ -56,7 +60,6 @@ final public class StringQueryUtil { | |||||||
| 		Object parameter = accessor.getBindableValue(index); | 		Object parameter = accessor.getBindableValue(index); | ||||||
| 		String parameterValue = "null"; | 		String parameterValue = "null"; | ||||||
| 
 | 
 | ||||||
| 		// noinspection ConstantConditions |  | ||||||
| 		if (parameter != null) { | 		if (parameter != null) { | ||||||
| 
 | 
 | ||||||
| 			parameterValue = convert(parameter); | 			parameterValue = convert(parameter); | ||||||
|  | |||||||
| @ -129,6 +129,18 @@ public class ElasticsearchStringQueryUnitTests extends ElasticsearchStringQueryU | |||||||
| 				"{ 'bool' : { 'must' : { 'terms' : { 'name' : [\"hello \\\"Stranger\\\"\",\"Another string\"] } } } }"); | 				"{ 'bool' : { 'must' : { 'terms' : { 'name' : [\"hello \\\"Stranger\\\"\",\"Another string\"] } } } }"); | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
|  | 	@Test // #2326 | ||||||
|  | 	@DisplayName("should escape backslashes in collection query parameters") | ||||||
|  | 	void shouldEscapeBackslashesInCollectionQueryParameters() throws NoSuchMethodException { | ||||||
|  | 
 | ||||||
|  | 		final List<String> parameters = Arrays.asList("param\\1", "param\\2"); | ||||||
|  | 		List<String> params = new ArrayList<>(parameters); | ||||||
|  | 		org.springframework.data.elasticsearch.core.query.Query query = createQuery("findByNameIn", params); | ||||||
|  | 
 | ||||||
|  | 		assertThat(query).isInstanceOf(StringQuery.class); | ||||||
|  | 		assertThat(((StringQuery) query).getSource()).isEqualTo( | ||||||
|  | 			"{ 'bool' : { 'must' : { 'terms' : { 'name' : [\"param\\\\1\",\"param\\\\2\"] } } } }"); | ||||||
|  | 	} | ||||||
| 	private org.springframework.data.elasticsearch.core.query.Query createQuery(String methodName, Object... args) | 	private org.springframework.data.elasticsearch.core.query.Query createQuery(String methodName, Object... args) | ||||||
| 			throws NoSuchMethodException { | 			throws NoSuchMethodException { | ||||||
| 
 | 
 | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user