Skip to content

Commit

Permalink
[context] Prevent unintended usage of JDK 21 feature (closes #2117)
Browse files Browse the repository at this point in the history
- import kotlin.collections.removeFirst as removeFirstKt
- Set <release> instead of <source> and <target>
- Downgrade JTE to 2x
  • Loading branch information
tipsy committed Feb 23, 2024
1 parent 8f60d44 commit 2b4c30d
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 7 deletions.
4 changes: 1 addition & 3 deletions .github/workflows/publish-snapshots.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@ jobs:
if: |
github.repository == 'javalin/javalin' &&
!contains(github.event.head_commit.message, '[maven-release-plugin] prepare release')
name: Publish snapshot
runs-on: ubuntu-latest
steps:
Expand All @@ -19,7 +17,7 @@ jobs:
uses: actions/setup-java@v4
with:
distribution: 'zulu'
java-version: 21
java-version: 11
- name: Grant execute permission for mvnw
run: chmod +x ./mvnw
- uses: s4u/maven-settings-action@v3.0.0
Expand Down
2 changes: 1 addition & 1 deletion javalin-rendering/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

<properties>
<copy-build-resources.skip>false</copy-build-resources.skip>
<jte.version>3.0.2</jte.version>
<jte.version>2.3.2</jte.version>
</properties>

<dependencies>
Expand Down
3 changes: 2 additions & 1 deletion javalin/src/main/java/io/javalin/http/Cookie.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package io.javalin.http
import jakarta.servlet.http.HttpServletRequest
import jakarta.servlet.http.HttpServletResponse
import jakarta.servlet.http.Cookie as ServletCookie
import kotlin.collections.removeFirst as removeFirstKt

const val SAME_SITE = "SameSite"

Expand Down Expand Up @@ -86,7 +87,7 @@ fun HttpServletResponse.setJavalinCookie(javalinCookie: Cookie) {
this.addCookie(cookie) // we rely on this method for formatting the cookie header
(this.getHeaders(Header.SET_COOKIE) ?: listOf()).toMutableList().let { cookies -> // mutable list of all cookies
cookies.removeIf { it.startsWith("${cookie.name}=") && !it.contains(cookie.value) } // remove old cookie if duplicate name
cookies.removeFirst()?.let { first -> this.setHeader(Header.SET_COOKIE, first.addSameSite(javalinCookie)) } // remove first cookie and use it to clear the header
cookies.removeFirstKt()?.let { first -> this.setHeader(Header.SET_COOKIE, first.addSameSite(javalinCookie)) } // remove first cookie and use it to clear the header
cookies.forEach { remaining -> this.addHeader(Header.SET_COOKIE, remaining.addSameSite(javalinCookie)) } // add all remaining cookies
}

Expand Down
3 changes: 1 addition & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -303,8 +303,7 @@
</execution>
</executions>
<configuration>
<source>${jdk.version}</source>
<target>${jdk.version}</target>
<release>${jdk.version}</release>
</configuration>
</plugin>
<plugin>
Expand Down

0 comments on commit 2b4c30d

Please sign in to comment.