Skip to content

Commit

Permalink
fix: TAG and TEXT fields should be escaped by default when using QBE (r…
Browse files Browse the repository at this point in the history
…esolved gh-451)
  • Loading branch information
bsbodden committed Jun 5, 2024
1 parent 356bef3 commit 1755c99
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,9 @@ public Node processExample(Example<E> example, Node rootNode) {
}
} else {
if (matchingAll) {
rootNode = QueryBuilders.intersect(rootNode).add(fieldName, "{" + value + "}");
rootNode = QueryBuilders.intersect(rootNode).add(fieldName, "{" + QueryUtils.escape(value) + "}");
} else {
rootNode = QueryBuilders.union(rootNode).add(fieldName, "{" + value + "}");
rootNode = QueryBuilders.union(rootNode).add(fieldName, "{" + QueryUtils.escape(value) + "}");
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@

import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
import static org.junit.jupiter.api.Assertions.assertAll;
import static org.junit.jupiter.api.Assertions.*;
import static org.junit.jupiter.api.Assertions.assertEquals;

public class RedisDocumentQueryByExampleTest extends AbstractBaseDocumentTest {
@Autowired
Expand Down Expand Up @@ -542,4 +543,28 @@ void testFindByShouldApplyProjection() {
assertThat(doc1.getANumber()).isNotNull();
assertThat(doc1.getTitle()).isNull();
}

@Test
void testTagEscapeCharsWithProjection() {
Company template = new Company();
template.setEmail("[email protected]");

Example<Company> example = Example.of(template);

Company result = companyRepository.findBy(example, it -> it.project("name").firstValue());

assertThat(result.getName()).isEqualTo("RedisInc");
}

@Test
void testTagEscapeCharsFindByShouldReturnOneResult() {
Company template = new Company();
template.setEmail("[email protected]");

Example<Company> example = Example.of(template);

Company result = companyRepository.findBy(example, FetchableFluentQuery::oneValue);
assertThat(result).isNotNull().hasFieldOrPropertyWithValue("email", "[email protected]");
assertThat(result.getName()).isEqualTo("RedisInc");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -454,4 +454,28 @@ void testFindByShouldApplyProjection() {
assertThat(doc1.getTitle()).isNull();
}

@Test
void testTagEscapeCharsWithProjection() {
Company template = new Company();
template.setEmail("[email protected]");

Example<Company> example = Example.of(template);

Company result = companyRepository.findBy(example, it -> it.project("name").firstValue());

assertThat(result.getName()).isEqualTo("RedisInc");
}

@Test
void testTagEscapeCharsFindByShouldReturnOneResult() {
Company template = new Company();
template.setEmail("[email protected]");

Example<Company> example = Example.of(template);

Company result = companyRepository.findBy(example, FetchableFluentQuery::oneValue);
assertThat(result).isNotNull().hasFieldOrPropertyWithValue("email", "[email protected]");
assertThat(result.getName()).isEqualTo("RedisInc");
}

}

0 comments on commit 1755c99

Please sign in to comment.