Gracefully handle duplicate query keys in contextual services pipeline (#2697)
Fixes #2696
This commit is contained in:
Родитель
5058a75f27
Коммит
b353858b3b
|
@ -54,12 +54,16 @@ public class BuildReportingUrl {
|
|||
throw new InvalidUrlException("Reporting URL null or missing: " + reportingUrl);
|
||||
}
|
||||
|
||||
if (this.reportingUrl.getQuery() == null) {
|
||||
queryParams = new HashMap<>();
|
||||
} else {
|
||||
queryParams = Arrays.stream(this.reportingUrl.getQuery().split("&"))
|
||||
.map(param -> param.split("="))
|
||||
.collect(Collectors.toMap(item -> item[0], item -> item.length > 1 ? item[1] : ""));
|
||||
try {
|
||||
if (this.reportingUrl.getQuery() == null) {
|
||||
queryParams = new HashMap<>();
|
||||
} else {
|
||||
queryParams = Arrays.stream(this.reportingUrl.getQuery().split("&"))
|
||||
.map(param -> param.split("="))
|
||||
.collect(Collectors.toMap(item -> item[0], item -> item.length > 1 ? item[1] : ""));
|
||||
}
|
||||
} catch (IllegalStateException e) {
|
||||
throw new InvalidUrlException("Reporting URL contains duplicate query keys: " + reportingUrl);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -0,0 +1,15 @@
|
|||
package com.mozilla.telemetry.contextualservices;
|
||||
|
||||
import static org.junit.Assert.assertThrows;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
public class BuildReportingUrlTest {
|
||||
|
||||
@Test
|
||||
public void testDuplicateQueryKeys() {
|
||||
assertThrows(BuildReportingUrl.InvalidUrlException.class,
|
||||
() -> new BuildReportingUrl("https://example.com?foo=bar&foo=bar"));
|
||||
}
|
||||
|
||||
}
|
Загрузка…
Ссылка в новой задаче