Skip to content

Commit

Permalink
only allow digits in url timestamp
Browse files Browse the repository at this point in the history
  • Loading branch information
VictorHarbo committed Dec 9, 2024
1 parent 2ca101e commit 5dd331a
Showing 1 changed file with 19 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ public Response getResolvedTimeGate(@Context UriInfo uriInfo, @Context HttpServl

if (acceptDatetime == null || acceptDatetime.isEmpty()){
acceptDatetime = DateUtils.formatDate(new Date(System.currentTimeMillis()));
log.warn("Requested memento without accept-datetime header. The newest memento is returned.");
log.info("Requested memento without accept-datetime header. The newest memento is returned.");
}

URI uri = PathResolver.mementoAPIResolver("/memento/", uriInfo, url);
Expand All @@ -151,17 +151,31 @@ public Response getResolvedTimeGate(@Context UriInfo uriInfo, @Context HttpServl
* @throws Exception
*/
@GET
@Path("/{timestamp}/{url:.+}")
@Path("/{timestamp:\\d+}/{url:.+}")
public Response getResolvedTimeGateFromPathTimestamp(@Context UriInfo uriInfo, @Context HttpServletRequest httpRequest, @PathParam("url") String url, @PathParam("timestamp")
String timestamp) throws Exception {
/*if (!StringUtils.isNumeric(timestamp)){
log.debug("No timestamp is available. The whole URL is part of a memento.");
// Combine URL prefix with url as no timestamp is present and the variable timestamp probably contains https/
StringJoiner joiner = new StringJoiner("/");
joiner.add(timestamp).add(url);
// When this happens we need a new timestamp.
String currentTime = DateUtils.formatDate(new Date(System.currentTimeMillis()));
URI uri = PathResolver.mementoAPIResolver("/memento/", uriInfo, joiner.toString());
return DatetimeNegotiation.getMemento(String.valueOf(uri), currentTime);
}*/


if (timestamp == null || timestamp.isEmpty()){
timestamp = DateUtils.formatDate(new Date(System.currentTimeMillis()));
log.warn("Requested memento without timestamp info. The newest memento is returned.");
log.info("Requested memento without timestamp info. The newest memento is returned.");
}


URI uri = PathResolver.mementoAPIResolver("/memento/", uriInfo, url);
Response timeGate = DatetimeNegotiation.getMemento(String.valueOf(uri), timestamp);
return timeGate;
return DatetimeNegotiation.getMemento(String.valueOf(uri), timestamp);
}

/**
Expand Down

0 comments on commit 5dd331a

Please sign in to comment.