Skip to content
Snippets Groups Projects

Iss #89 - Replace regex in commons to address vulnerable regex

Merged Iss #89 - Replace regex in commons to address vulnerable regex
All threads resolved!
Merged Martin Lowe requested to merge malowe/eclipsefdn-api-common:malowe/main/89 into main
All threads resolved!
3 files
+ 94
7
Compare changes
  • Side-by-side
  • Inline
Files
3
@@ -15,11 +15,13 @@ import java.util.ArrayList;
import java.util.List;
import java.util.Map.Entry;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import javax.annotation.PostConstruct;
import javax.enterprise.context.ApplicationScoped;
import javax.enterprise.inject.Instance;
import javax.inject.Inject;
import javax.ws.rs.core.MultivaluedHashMap;
import javax.ws.rs.core.MultivaluedMap;
import org.eclipsefoundation.core.namespace.UrlParameterNamespace;
@@ -74,6 +76,23 @@ public class ParameterHelper {
}, MultivaluedMapImpl<String, String>::new));
}
/**
* Parses a decoded query string to create a query map for use in lookups.
*
* @param query the decoded query string for a request
* @return map of param names to the associated values
*/
public static MultivaluedMap<String, String> parseQueryString(String query) {
if (query == null) {
return new MultivaluedHashMap<>();
}
return Stream
.of(query.split("&"))
.map(q -> q.split("=", 2))
.filter(a -> a.length == 2)
.collect(MultivaluedHashMap::new, (multimap, input) -> multimap.add(input[0], input[1]), MultivaluedMap::putAll);
}
/**
* Returns a list of parameter names, as generated from reading in the parameters present in the
* {@link UrlParameterNamespace} implementations.
Loading