Skip to content

Commit 7dd4186

Browse files
committed
Taken into account copilot review
1 parent 8b4fa12 commit 7dd4186

9 files changed

Lines changed: 49 additions & 53 deletions

File tree

org.restlet.ext.freemarker/src/test/java/org/restlet/ext/freemarker/FreeMarkerTestCase.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
*/
99
package org.restlet.ext.freemarker;
1010

11-
import static freemarker.template.Configuration.DEFAULT_INCOMPATIBLE_IMPROVEMENTS;
1211
import static org.junit.jupiter.api.Assertions.assertEquals;
1312
import static org.junit.jupiter.api.Assertions.assertNotNull;
1413
import static org.junit.jupiter.api.Assertions.assertNull;

org.restlet.ext.jackson/src/test/java/org/restlet/ext/jackson/JacksonTestCase.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,7 @@ protected void assertEquals(MyException me1, MyException me2) {
205205
assertEquals(me1.getCustomer(), me2.getCustomer());
206206
}
207207

208-
private String normalizeLineEndings(String text) {
209-
return text.replace("\r\n", "\n").replace('\r', '\n');
210-
}
208+
private String normalizeLineEndings(String text) {
209+
return text.replace("\r\n", "\n").replace('\r', '\n');
210+
}
211211
}

org.restlet.ext.spring/src/main/java/org/restlet/ext/spring/SpringBeanFinder.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,8 +92,7 @@ && getApplicationContext().containsBean(requiredBeanName)) {
9292
}
9393
}
9494

95-
@NonNull
96-
private String getRequiredBeanName() {
95+
@NonNull private String getRequiredBeanName() {
9796
String currentBeanName = getBeanName();
9897
if (currentBeanName == null) {
9998
throw new IllegalStateException("beanName");

org.restlet.ext.spring/src/main/java/org/restlet/ext/spring/SpringBeanRouter.java

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -270,40 +270,35 @@ public void setApplicationContext(@NonNull ApplicationContext applicationContext
270270
this.applicationContext = applicationContext;
271271
}
272272

273-
@NonNull
274-
private String requiredBeanName(String beanName) {
273+
@NonNull private String requiredBeanName(String beanName) {
275274
if (beanName == null) {
276275
throw new IllegalStateException("beanName");
277276
}
278277
return beanName;
279278
}
280279

281-
@NonNull
282-
private BeanFactory requiredBeanFactory(BeanFactory beanFactory) {
280+
@NonNull private BeanFactory requiredBeanFactory(BeanFactory beanFactory) {
283281
if (beanFactory == null) {
284282
throw new IllegalStateException("beanFactory");
285283
}
286284
return beanFactory;
287285
}
288286

289-
@NonNull
290-
private ListableBeanFactory requiredListableBeanFactory(ListableBeanFactory beanFactory) {
287+
@NonNull private ListableBeanFactory requiredListableBeanFactory(ListableBeanFactory beanFactory) {
291288
if (beanFactory == null) {
292289
throw new IllegalStateException("beanFactory");
293290
}
294291
return beanFactory;
295292
}
296293

297-
@NonNull
298-
private Class<?> requiredBeanClass(Class<?> beanClass) {
294+
@NonNull private Class<?> requiredBeanClass(Class<?> beanClass) {
299295
if (beanClass == null) {
300296
throw new IllegalStateException("beanClass");
301297
}
302298
return beanClass;
303299
}
304300

305-
@NonNull
306-
private ApplicationContext requiredApplicationContext() {
301+
@NonNull private ApplicationContext requiredApplicationContext() {
307302
ApplicationContext currentApplicationContext = this.applicationContext;
308303
if (currentApplicationContext == null) {
309304
throw new IllegalStateException("applicationContext");

org.restlet.ext.spring/src/main/java/org/restlet/ext/spring/SpringResource.java

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -81,8 +81,7 @@ public boolean exists() {
8181
* @return The description.
8282
*/
8383
@Override
84-
@NonNull
85-
public String getDescription() {
84+
@NonNull public String getDescription() {
8685
return this.description;
8786
}
8887

@@ -91,8 +90,7 @@ public String getDescription() {
9190
* multiple times.
9291
*/
9392
@Override
94-
@NonNull
95-
public InputStream getInputStream() throws IOException, IllegalStateException {
93+
@NonNull public InputStream getInputStream() throws IOException, IllegalStateException {
9694
if (this.read && this.representation.isTransient()) {
9795
throw new IllegalStateException(
9896
"Representation has already been read and is transient.");

org.restlet.ext.spring/src/test/java/org/restlet/ext/spring/SpringBeanFinderTestCase.java

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -205,42 +205,37 @@ void testUsesApplicationContextIfPresent() {
205205
assertInstanceOf(SomeResource.class, actual, "Resource not the correct type");
206206
}
207207

208-
@NonNull
209-
private StaticApplicationContext requiredApplicationContext() {
208+
@NonNull private StaticApplicationContext requiredApplicationContext() {
210209
StaticApplicationContext currentApplicationContext = this.applicationContext;
211210
if (currentApplicationContext == null) {
212211
throw new IllegalStateException("applicationContext");
213212
}
214213
return currentApplicationContext;
215214
}
216215

217-
@NonNull
218-
private DefaultListableBeanFactory requiredBeanFactory() {
216+
@NonNull private DefaultListableBeanFactory requiredBeanFactory() {
219217
DefaultListableBeanFactory currentBeanFactory = this.beanFactory;
220218
if (currentBeanFactory == null) {
221219
throw new IllegalStateException("beanFactory");
222220
}
223221
return currentBeanFactory;
224222
}
225223

226-
@NonNull
227-
private String requiredBeanName(String beanName) {
224+
@NonNull private String requiredBeanName(String beanName) {
228225
if (beanName == null) {
229226
throw new IllegalStateException("beanName");
230227
}
231228
return beanName;
232229
}
233230

234-
@NonNull
235-
private Class<SomeResource> requiredResourceClass(Class<SomeResource> resourceClass) {
231+
@NonNull private Class<SomeResource> requiredResourceClass(Class<SomeResource> resourceClass) {
236232
if (resourceClass == null) {
237233
throw new IllegalStateException("resourceClass");
238234
}
239235
return resourceClass;
240236
}
241237

242-
@NonNull
243-
private Class<?> requiredAnyClass(Class<?> resourceClass) {
238+
@NonNull private Class<?> requiredAnyClass(Class<?> resourceClass) {
244239
if (resourceClass == null) {
245240
throw new IllegalStateException("resourceClass");
246241
}

org.restlet.ext.spring/src/test/java/org/restlet/ext/spring/SpringBeanRouterTestCase.java

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ void tearDownEach() {
148148
void testExplicitAttachmentsMayBeRestlets() {
149149
String expected = "/protected/timber";
150150
this.router.setAttachments(
151-
Collections.singletonMap(requiredString(expected), requiredString("timber")));
151+
Collections.singletonMap(requiredString(expected), requiredString("timber")));
152152
registerBeanDefinition("timber", null, TestAuthenticator.class, null);
153153

154154
doPostProcess();
@@ -161,7 +161,7 @@ void testExplicitAttachmentsMayBeRestlets() {
161161
@Test
162162
void testExplicitAttachmentsTrumpBeanNames() {
163163
this.router.setAttachments(
164-
Collections.singletonMap(requiredString(ORE_URI), requiredString("fish")));
164+
Collections.singletonMap(requiredString(ORE_URI), requiredString("fish")));
165165
RouteList actualRoutes = actualRoutes();
166166
assertEquals(2, actualRoutes.size(), "Wrong number of routes");
167167

@@ -173,8 +173,7 @@ void testExplicitAttachmentsTrumpBeanNames() {
173173
@Test
174174
void testExplicitRoutingForNonResourceNonRestletBeansFails() {
175175
this.router.setAttachments(
176-
Collections.singletonMap(
177-
requiredString("/fail"), requiredString("someOtherBean")));
176+
Collections.singletonMap(requiredString("/fail"), requiredString("someOtherBean")));
178177

179178
IllegalStateException ise = assertThrows(IllegalStateException.class, this::doPostProcess);
180179
assertEquals(
@@ -270,8 +269,8 @@ void testRoutingIncludesSpringRouterStyleExplicitlyMappedBeans() {
270269

271270
String expectedTemplate = "/renewable/timber/{farm_type}";
272271
router.setAttachments(
273-
Collections.singletonMap(
274-
requiredString(expectedTemplate), requiredString("timber")));
272+
Collections.singletonMap(
273+
requiredString(expectedTemplate), requiredString("timber")));
275274
final RouteList actualRoutes = actualRoutes();
276275

277276
assertEquals(3, actualRoutes.size(), "Wrong number of routes");

org.restlet/src/main/java/org/restlet/data/Reference.java

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -717,8 +717,8 @@ private String encodeInvalidCharacters(String uriRef) throws IllegalArgumentExce
717717
Level.FINE,
718718
"Invalid character detected in URI reference at index \"{0}\": \"{1}\". It will be automatically encoded.",
719719
new Object[] {i, character});
720-
} else if ((character == '%') && (i > uriRef.length() - 2)) {
721-
// A percent encoding character has been detected but
720+
} else if ((character == '%') && (i >= uriRef.length() - 2)) {
721+
// A percent-encoding character has been detected but
722722
// without the necessary two hexadecimal digits following
723723
valid = false;
724724
Context.getCurrentLogger()
@@ -734,7 +734,7 @@ private String encodeInvalidCharacters(String uriRef) throws IllegalArgumentExce
734734

735735
for (int i = 0; (i < uriRef.length()); i++) {
736736
if (isValid(uriRef.charAt(i))) {
737-
if ((uriRef.charAt(i) == '%') && (i > uriRef.length() - 2)) {
737+
if ((uriRef.charAt(i) == '%') && (i >= uriRef.length() - 2)) {
738738
sb.append("%25");
739739
} else {
740740
sb.append(uriRef.charAt(i));
@@ -2961,6 +2961,11 @@ private void validateIpV6(String ipV6) {
29612961
throw new IllegalArgumentException("Invalid IPv6 address");
29622962
}
29632963

2964+
// Three or more consecutive colons are never valid.
2965+
if (ipV6.contains(":::")) {
2966+
throw new IllegalArgumentException("Invalid IPv6 address format");
2967+
}
2968+
29642969
int doubleColonCount = countDoubleColons(ipV6);
29652970
if (doubleColonCount > 1) {
29662971
throw new IllegalArgumentException("Invalid IPv6 address format");
@@ -2994,12 +2999,11 @@ private int countDoubleColons(String ipV6) {
29942999
}
29953000

29963001
/**
2997-
* Validates the number of hex groups in an IPv6 address.
2998-
* Without "::" compression, exactly {@code maxHexGroups} groups are required.
2999-
* With "::", at most {@code maxHexGroups - 1} explicit groups are allowed.
3002+
* Validates the number of hex groups in an IPv6 address. Without "::" compression, exactly
3003+
* {@code maxHexGroups} groups are required. With "::", at most {@code maxHexGroups - 1}
3004+
* explicit groups are allowed.
30003005
*/
3001-
private void validateIpV6GroupCount(
3002-
String[] parts, int doubleColonCount, boolean hasIpV4Tail) {
3006+
private void validateIpV6GroupCount(String[] parts, int doubleColonCount, boolean hasIpV4Tail) {
30033007
int maxHexGroups = hasIpV4Tail ? 6 : 8;
30043008
int hexPartCount = hasIpV4Tail ? parts.length - 1 : parts.length;
30053009

@@ -3069,11 +3073,11 @@ private void validateIpV4(final String ipV4) {
30693073
* @param scheme The scheme to validate.
30703074
*/
30713075
private void validateScheme(final String scheme) {
3072-
if (scheme == null || scheme.isEmpty()) {
3076+
if (scheme == null) {
30733077
return;
30743078
}
30753079

3076-
if (!SCHEME_REGEXP.matcher(scheme).matches()) {
3080+
if (scheme.isEmpty() || !SCHEME_REGEXP.matcher(scheme).matches()) {
30773081
throw new IllegalArgumentException("Invalid scheme format");
30783082
}
30793083
}

org.restlet/src/test/java/org/restlet/data/ReferenceTestCase.java

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ class ReferenceTestCase {
3030

3131
protected static final String DEFAULT_SCHEME = "http";
3232

33-
protected static final String DEFAULT_SCHEMEPART = "//";
33+
protected static final String DEFAULT_SCHEME_PART = "//";
3434

3535
/**
3636
* Returns a reference initialized with http://restlet.org.
@@ -51,7 +51,7 @@ protected Reference getDefaultReference() {
5151
protected Reference getReference() {
5252
final Reference ref = new Reference();
5353
ref.setScheme(DEFAULT_SCHEME);
54-
ref.setSchemeSpecificPart(DEFAULT_SCHEMEPART);
54+
ref.setSchemeSpecificPart(DEFAULT_SCHEME_PART);
5555
return ref;
5656
}
5757

@@ -535,11 +535,12 @@ void testProtocolConstructors() {
535535
void testQuery() {
536536

537537
Reference ref1 = new Reference("http://localhost/search?q=anythingelse%");
538-
String query = ref1.getQuery();
539-
assertEquals("q=anythingelse%25", query);
538+
assertEquals("q=anythingelse%25", ref1.getQuery());
539+
assertEquals("anythingelse%", ref1.getQueryAsForm().getFirstValue("q"));
540540

541-
Form queryForm = ref1.getQueryAsForm();
542-
assertEquals("anythingelse%", queryForm.getFirstValue("q"));
541+
Reference ref2 = new Reference("http://localhost/search?q=anythingelse%a");
542+
assertEquals("q=anythingelse%25a", ref2.getQuery());
543+
assertEquals("anythingelse%a", ref2.getQueryAsForm().getFirstValue("q"));
543544

544545
Form extJsQuery = new Form("&_dc=1244741620627&callback=stcCallback1001");
545546
assertEquals("1244741620627", extJsQuery.getFirstValue("_dc"));
@@ -745,6 +746,8 @@ class TestFailures {
745746
"https://[1:2:3:4:5:6:7:8:9]",
746747
"https://[1::1::1]",
747748
"https://[1:2:3:]",
749+
"https://[1:::]",
750+
"https://[:::1]",
748751
"https://[ffff::127.0.0.4000]",
749752
"https://[0:0::vulndetector.com]:80",
750753
"https://[2001:db8::vulndetector.com]",
@@ -758,7 +761,11 @@ void shouldFailWhenParsingIncorrectHosts(String url) {
758761

759762
@ParameterizedTest
760763
@ValueSource(
761-
strings = {"https>://vulndetector.com/path", "https%25://vulndetector.com/path"})
764+
strings = {
765+
"https>://vulndetector.com/path",
766+
"https%25://vulndetector.com/path",
767+
"://vulndetector.com/path",
768+
})
762769
void shouldFailWhenParsingIncorrectScheme(String url) {
763770
final Reference reference = new Reference(url);
764771
assertThrows(IllegalArgumentException.class, reference::getScheme);

0 commit comments

Comments
 (0)