Skip to content

Commit

Permalink
Fix use of groups in custom search request mapping. See #700
Browse files Browse the repository at this point in the history
  • Loading branch information
theotherp committed Jun 13, 2022
1 parent 0a30ef0 commit f3c6544
Show file tree
Hide file tree
Showing 8 changed files with 37 additions and 23 deletions.
24 changes: 12 additions & 12 deletions core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@
<!-- We use logback but due to a CVE in previous versions we force this dependency -->
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-api</artifactId>
<version>2.17.1</version>
<version>2.17.2</version>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
Expand Down Expand Up @@ -248,7 +248,7 @@
<dependency>
<groupId>com.github.briandilley.jsonrpc4j</groupId>
<artifactId>jsonrpc4j</artifactId>
<version>1.5.3</version>
<version>1.6</version>
<exclusions>
<exclusion>
<artifactId>jackson-core</artifactId>
Expand Down Expand Up @@ -277,14 +277,14 @@
<dependency>
<groupId>com.squareup.okhttp3</groupId>
<artifactId>logging-interceptor</artifactId>
<version>3.14.1</version>
<version>4.9.3</version>
</dependency>


<dependency>
<groupId>net.sf.jopt-simple</groupId>
<artifactId>jopt-simple</artifactId>
<version>4.9</version>
<version>5.0.4</version>
</dependency>
<dependency>
<groupId>org.jsoup</groupId>
Expand All @@ -294,7 +294,7 @@
<dependency>
<groupId>net.jodah</groupId>
<artifactId>expiringmap</artifactId>
<version>0.5.8</version>
<version>0.5.10</version>
</dependency>
<dependency>
<groupId>com.github.beothorn</groupId>
Expand All @@ -320,7 +320,7 @@
<dependency>
<groupId>joda-time</groupId>
<artifactId>joda-time</artifactId>
<version>2.10.1</version>
<version>2.10.14</version>
<scope>compile</scope>
</dependency>

Expand All @@ -332,7 +332,7 @@
<dependency>
<groupId>org.javers</groupId>
<artifactId>javers-core</artifactId>
<version>5.10.1</version>
<version>6.6.5</version>
</dependency>


Expand All @@ -346,7 +346,7 @@
<dependency>
<groupId>org.springdoc</groupId>
<artifactId>springdoc-openapi-ui</artifactId>
<version>1.6.6</version>
<version>1.6.8</version>
</dependency>

<!--logging-->
Expand Down Expand Up @@ -384,7 +384,7 @@
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.7.25</version>
<version>1.7.36</version>
</dependency>
<dependency>
<groupId>org.nzbhydra</groupId>
Expand All @@ -402,7 +402,7 @@
<dependency>
<groupId>org.reflections</groupId>
<artifactId>reflections</artifactId>
<version>0.9.11</version>
<version>0.10.2</version>
</dependency>
<dependency>
<groupId>xmlunit</groupId>
Expand All @@ -413,7 +413,7 @@
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
<version>2.21.0</version>
<version>4.5.1</version>
<scope>test</scope>
</dependency>
<dependency>
Expand All @@ -425,7 +425,7 @@
<dependency>
<groupId>org.mock-server</groupId>
<artifactId>mockserver-netty</artifactId>
<version>5.11.2</version>
<version>5.13.2</version>
<scope>test</scope>
<exclusions>
<exclusion>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ private String mapValue(SearchRequest searchRequest, Mapping mapping, String val
replacementRegex = replacementRegex.replace("{episode}", searchRequest.getEpisode().get());
}
}
replacementRegex = replacementRegex.replaceAll("\\{(?<groupName>[^\\^}].*)}", "\\$\\{hydra${groupName}\\}");
replacementRegex = replacementRegex.replaceAll("\\{(?<groupName>[^\\}]*)\\}", "\\$\\{hydra${groupName}\\}");
logger.debug(LoggingMarkers.CUSTOM_MAPPING, "Mapping input \"{}\" using replacement regex \"{}\"", value, replacementRegex);
mappedValue = mappedValue.replaceAll(mapping.getFromPattern().pattern(), replacementRegex);
logger.debug(LoggingMarkers.CUSTOM_MAPPING, "Mapped input \"{}\" to \"{}\"", value, mappedValue);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -189,8 +189,9 @@ protected boolean checkForCategoryShouldBeIgnored(SearchRequest searchRequest, M

protected boolean checkForCategoryDisabledForIndexer(SearchRequest searchRequest, Multiset<String> reasonsForRejection, SearchResultItem item) {
List<String> enabledCategories = item.getIndexer().getConfig().getEnabledCategories();
if (!item.getCategory().equals(CategoryProvider.naCategory) && !enabledCategories.isEmpty() && !enabledCategories.contains(item.getCategory().getName())) {
logger.debug(LoggingMarkers.RESULT_ACCEPTOR, "{} is in category {} disabled for indexer", item.getTitle(), item.getCategory().getName());
final String categoryName = item.getCategory().getName();
if (!item.getCategory().equals(CategoryProvider.naCategory) && !enabledCategories.isEmpty() && !enabledCategories.contains(categoryName)) {
logger.debug(LoggingMarkers.RESULT_ACCEPTOR, "{} is in category {} disabled for indexer {} (enabled are: {})", item.getTitle(), categoryName, item.getIndexer().getName(), enabledCategories);
reasonsForRejection.add("In forbidden category");
return false;
}
Expand Down
4 changes: 2 additions & 2 deletions core/src/main/java/org/nzbhydra/web/ErrorHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import net.logstash.logback.encoder.org.apache.commons.lang.exception.ExceptionUtils;
import org.apache.commons.lang3.exception.ExceptionUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.ConversionNotSupportedException;
Expand Down Expand Up @@ -206,4 +206,4 @@ public static class JsonExceptionResponse {
}


}
}
4 changes: 4 additions & 0 deletions core/src/main/resources/changelog.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@
{
"version": "v4.3.2",
"changes": [
{
"type": "fix",
"text": "Fix use of groups in custom search request mapping. See #700"
},
{
"type": "fix",
"text": "Fix download of backup files. See #772"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,5 +107,16 @@ public void shouldFindMatchingDatasetTitle() {
assertThat(testee.isDatasetMatch(searchRequest, mapping)).isFalse();
}

@Test
public void shouldReplaceAllCustomGroups() {
final SearchRequest searchRequest = new SearchRequest();
searchRequest.setTitle("Fairy Tail 49");
final CustomSearchRequestMapping.Mapping mapping = new CustomSearchRequestMapping.Mapping("TVSEARCH;TITLE;{title:Fairy Tail} {ep:[0-9]+};{title} german e{ep}");
assertThat(testee.isDatasetMatch(searchRequest, mapping)).isTrue();

testee.mapSearchRequest(searchRequest, mapping);
assertThat(searchRequest.getTitle()).isPresent().get().isEqualTo("Fairy Tail german e49");
}


}
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,6 @@
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.mockito.ArgumentMatchers.anyInt;
import static org.mockito.Matchers.any;
import static org.mockito.Matchers.eq;
import static org.mockito.Mockito.*;

//@RunWith(SpringRunner.class)
Expand Down
8 changes: 4 additions & 4 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -84,13 +84,13 @@
<spring.security.test.version>5.6.0</spring.security.test.version>
<jackson.version>2.13.0</jackson.version>
<lombok.version>1.18.2</lombok.version>
<logback.version>1.2.9</logback.version>
<logback.version>1.2.11</logback.version>
<guava.version>23.0</guava.version>
<junit.version>4.13.2</junit.version>
<okhttp.version>3.14.6</okhttp.version>
<logstash-logback-encoder.version>5.1</logstash-logback-encoder.version>
<okhttp.version>4.9.3</okhttp.version>
<logstash-logback-encoder.version>7.1.1</logstash-logback-encoder.version>
<commons-lang3.version>3.7</commons-lang3.version>
<commons-io.version>2.6</commons-io.version>
<commons-io.version>2.11.0</commons-io.version>
<flyway-core.version>6.2.0</flyway-core.version>
<jaxb.sun.core.version>2.3.0.1</jaxb.sun.core.version>
<jaxb.sun.impl.version>3.0.1</jaxb.sun.impl.version>
Expand Down

0 comments on commit f3c6544

Please sign in to comment.