Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SameSite is capital first letter only. #5473

Merged
merged 1 commit into from
Nov 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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