Skip to content

Commit

Permalink
SameSite is capital first letter only.
Browse files Browse the repository at this point in the history
Signed-off-by: jansupol <[email protected]>
  • Loading branch information
jansupol committed Nov 22, 2023
1 parent a0e9568 commit 71f6a08
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 5 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2010, 2021 Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2010, 2023 Oracle and/or its affiliates. All rights reserved.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0, which is available at
Expand All @@ -23,6 +23,8 @@
import org.glassfish.jersey.internal.LocalizationMessages;
import org.glassfish.jersey.spi.HeaderDelegateProvider;

import java.util.Locale;

import static org.glassfish.jersey.message.internal.Utils.throwIllegalArgumentExceptionIfNull;

/**
Expand Down Expand Up @@ -75,7 +77,7 @@ public String toString(final NewCookie cookie) {
}
if (cookie.getSameSite() != null) {
b.append(";SameSite=");
b.append(cookie.getSameSite());
b.append(getSameSite(cookie));
}
if (cookie.getExpiry() != null) {
b.append(";Expires=");
Expand All @@ -90,4 +92,9 @@ public NewCookie fromString(final String header) {
throwIllegalArgumentExceptionIfNull(header, LocalizationMessages.NEW_COOKIE_IS_NULL());
return HttpHeaderReader.readNewCookie(header);
}

private static String getSameSite(NewCookie cookie) {
final String siteName = cookie.getSameSite().name();
return siteName.charAt(0) + siteName.substring(1).toLowerCase(Locale.ROOT);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public class NewCookieProviderTest {
public void SameSiteTest() {
final NewCookieProvider provider = new NewCookieProvider();
final String newCookieString = provider.toString(newCookie);
assertTrue(newCookieString.contains("SameSite=STRICT"));
assertTrue(newCookieString.contains("SameSite=Strict"));
assertEquals(NewCookie.SameSite.STRICT, provider.fromString(newCookieString).getSameSite());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ public void testNewCookieToString() {
cookie = new NewCookie("fred", "flintstone", null, null, 1,
"a modern stonage family", 60, null, false, false,
NewCookie.SameSite.STRICT);
expResult = "fred=flintstone;Version=1;Comment=\"a modern stonage family\";Max-Age=60;SameSite=STRICT";
expResult = "fred=flintstone;Version=1;Comment=\"a modern stonage family\";Max-Age=60;SameSite=Strict";
assertEquals(expResult, cookie.toString());
}

Expand All @@ -217,7 +217,7 @@ public void testNewCookieValueOf() {
assertTrue(cookie.isSecure());

cookie = NewCookie.valueOf(
"fred=flintstone;Version=1;Comment=\"a modern stonage family\";Max-Age=60;Secure;SameSite=NONE");
"fred=flintstone;Version=1;Comment=\"a modern stonage family\";Max-Age=60;Secure;SameSite=None");
assertEquals("fred", cookie.getName());
assertEquals("flintstone", cookie.getValue());
assertEquals("a modern stonage family", cookie.getComment());
Expand Down

0 comments on commit 71f6a08

Please sign in to comment.