File tree Expand file tree Collapse file tree 2 files changed +11
-4
lines changed
main/java/org/springframework/http
test/java/org/springframework/http Expand file tree Collapse file tree 2 files changed +11
-4
lines changed Original file line number Diff line number Diff line change @@ -65,6 +65,7 @@ public ResourceRegion toResourceRegion(Resource resource) {
65
65
long contentLength = getLengthFor (resource );
66
66
long start = getRangeStart (contentLength );
67
67
long end = getRangeEnd (contentLength );
68
+ Assert .isTrue (start < contentLength , "'position' exceeds the resource length " + contentLength );
68
69
return new ResourceRegion (resource , start , end - start + 1 );
69
70
}
70
71
Original file line number Diff line number Diff line change @@ -158,17 +158,23 @@ public void toResourceRegionIllegalLength() {
158
158
ByteArrayResource resource = mock (ByteArrayResource .class );
159
159
given (resource .contentLength ()).willReturn (-1L );
160
160
HttpRange range = HttpRange .createByteRange (0 , 9 );
161
- assertThatIllegalArgumentException ().isThrownBy (() ->
162
- range .toResourceRegion (resource ));
161
+ assertThatIllegalArgumentException ().isThrownBy (() -> range .toResourceRegion (resource ));
163
162
}
164
163
165
164
@ Test
166
165
public void toResourceRegionExceptionLength () throws IOException {
167
166
InputStreamResource resource = mock (InputStreamResource .class );
168
167
given (resource .contentLength ()).willThrow (IOException .class );
169
168
HttpRange range = HttpRange .createByteRange (0 , 9 );
170
- assertThatIllegalArgumentException ().isThrownBy (() ->
171
- range .toResourceRegion (resource ));
169
+ assertThatIllegalArgumentException ().isThrownBy (() -> range .toResourceRegion (resource ));
170
+ }
171
+
172
+ @ Test // gh-23576
173
+ public void toResourceRegionStartingAtResourceByteCount () {
174
+ byte [] bytes = "Spring Framework" .getBytes (StandardCharsets .UTF_8 );
175
+ ByteArrayResource resource = new ByteArrayResource (bytes );
176
+ HttpRange range = HttpRange .createByteRange (resource .contentLength ());
177
+ assertThatIllegalArgumentException ().isThrownBy (() -> range .toResourceRegion (resource ));
172
178
}
173
179
174
180
@ Test
You can’t perform that action at this time.
0 commit comments