Skip to content

Commit

Permalink
Merge branch 'escapes-for-parse-filter' of JulianKniephoff/opencast i…
Browse files Browse the repository at this point in the history
…nto r/16.x

Pull request opencast#6111

  Treat `filter` parameter elements in admin UI APIs as URL encoded
  • Loading branch information
gregorydlogan committed Nov 5, 2024
2 parents 8d2ab2b + 148bea6 commit 0598f36
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
package org.opencastproject.adminui.endpoint;

import org.opencastproject.adminui.exception.JsonCreationException;
import org.opencastproject.index.service.util.RestUtils;
import org.opencastproject.list.impl.ResourceListQueryImpl;
import org.opencastproject.list.query.StringListFilter;

Expand Down Expand Up @@ -86,16 +87,8 @@ public static <T> JSONObject generateJSONObject(Map<String, T> list) throws Json
* The query to update with the filters
*/
public static void addRequestFiltersToQuery(final String filterString, ResourceListQueryImpl query) {
if (filterString != null) {
String[] filters = filterString.split(",");
for (String filter : filters) {
String[] splitFilter = filter.split(":", 2);
if (splitFilter != null && splitFilter.length == 2) {
String key = splitFilter[0].trim();
String value = splitFilter[1].trim();
query.addFilter(new StringListFilter(key, value));
}
}
for (var filter : RestUtils.parseFilter(filterString).entrySet()) {
query.addFilter(new StringListFilter(filter.getKey(), filter.getValue()));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@
import com.entwinemedia.fn.data.json.Jsons;

import org.apache.commons.collections4.ComparatorUtils;
import org.apache.commons.lang3.StringUtils;
import org.osgi.service.component.annotations.Activate;
import org.osgi.service.component.annotations.Component;
import org.osgi.service.component.annotations.Reference;
Expand All @@ -69,6 +70,7 @@
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
Expand Down Expand Up @@ -161,7 +163,18 @@ public Response getGroups(@HeaderParam("Accept") String acceptHeader, @QueryPara
}

// The API currently does not offer full text search for groups
Map<String, String> filters = RestUtils.parseFilter(filter);
Map<String, String> filters = new HashMap<>();
if (StringUtils.isNotBlank(filter)) {
for (String f : filter.split(",")) {
String[] filterTuple = f.split(":");
if (filterTuple.length < 2) {
logger.debug("No value for filter '{}' in filters list: {}", filterTuple[0], filter);
continue;
}
// use substring because dates also contain : so there might be more than two parts
filters.put(filterTuple[0].trim(), f.substring(filterTuple[0].length() + 1).trim());
}
}
Optional<String> optNameFilter = Optional.ofNullable(filters.get(GroupsListQuery.FILTER_NAME_NAME));

Set<SortCriterion> sortCriteria = RestUtils.parseSortQueryParameter(sort);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@
import java.io.BufferedOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.net.URLDecoder;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
Expand Down Expand Up @@ -292,7 +294,8 @@ public static Map<String, String> parseFilter(String filter) {
continue;
}
// use substring because dates also contain : so there might be more than two parts
filters.put(filterTuple[0].trim(), f.substring(filterTuple[0].length() + 1).trim());
filters.put(filterTuple[0].trim(), URLDecoder.decode(f.substring(filterTuple[0].length() + 1).trim(),
StandardCharsets.UTF_8));
}
}
return filters;
Expand Down

0 comments on commit 0598f36

Please sign in to comment.