Skip to content

Commit

Permalink
fix: postgrest range is not correctly returned (#41)
Browse files Browse the repository at this point in the history
* fix: postgrest range is not correctly returned
  • Loading branch information
arnaud-thorel-of authored Aug 21, 2024
1 parent 89eeba4 commit d8c25cd
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public class HeaderRange {
* Range regexp
*/
@SuppressWarnings("java:S5852")
private static final Pattern REGEXP = Pattern.compile("(?<offset>\\d+)-(?<limit>\\d+)/(?<total>\\d+)");
private static final Pattern REGEXP = Pattern.compile("(?<offset>\\d+)-(?<limit>\\d+)/(?<total>[*\\d]+)");
/**
* Start of the range
*/
Expand All @@ -45,7 +45,12 @@ public static HeaderRange of(String rangeString) {
if (matcher.find()) {
range.offset = Integer.parseInt(matcher.group("offset"));
range.limit = Integer.parseInt(matcher.group("limit"));
range.totalElements = Long.parseLong(matcher.group("total"));
String total = matcher.group("total");
if (total.startsWith("*")) {
range.totalElements = range.limit - range.offset + 1;
} else {
range.totalElements = Long.parseLong(total);
}
}
return range;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,16 @@ void shouldCreateRange() {
assertEquals(25, count);
}

@Test
void shouldCreateRangeFromUnlimited() {
HeaderRange range = HeaderRange.of("0-24/*");
assertNotNull(range);
assertEquals(0, range.getOffset());
assertEquals(24, range.getLimit());
assertEquals(25, range.getTotalElements());

long count = range.getCount();
assertEquals(25, count);
}

}

0 comments on commit d8c25cd

Please sign in to comment.