Skip to content

Commit

Permalink
Merge pull request #16536 from FroMage/16534
Browse files Browse the repository at this point in the history
FlashScopeUtil: handle empty cookie bytes
  • Loading branch information
mkouba committed Apr 15, 2021
2 parents 57c70f8 + 1cfab0d commit 22d6cf3
Showing 1 changed file with 11 additions and 3 deletions.
Expand Up @@ -29,11 +29,19 @@ public static Object getFlash(RoutingContext event) {

public static void handleFlashCookie(RoutingContext event) {
Cookie cookie = event.request().getCookie(FLASH_COOKIE_NAME);
event.response().removeCookie(FLASH_COOKIE_NAME);
if (cookie != null) {
Map<String, Object> data = unmarshallMap(Base64.getDecoder().decode(cookie.getValue().getBytes()));
event.data().put(FLASH_CONTEXT_DATA_NAME, data);
byte[] bytes = cookie.getValue().getBytes();
if (bytes != null && bytes.length != 0) {
byte[] decoded = Base64.getDecoder().decode(bytes);
// API says it can't be null
if (decoded.length > 0) {
Map<String, Object> data = unmarshallMap(decoded);
event.data().put(FLASH_CONTEXT_DATA_NAME, data);
}
}
}
// must do this after we've read the value, otherwise we can't read it, for some reason
event.response().removeCookie(FLASH_COOKIE_NAME);
}

// we don't use json because quarkus-vertx-http does not depend on Jackson databind and therefore the
Expand Down

0 comments on commit 22d6cf3

Please sign in to comment.