Skip to content

Commit

Permalink
LDEV-3979 - keep servlet cookies and only extend and handle multiple …
Browse files Browse the repository at this point in the history
…cookie headers
  • Loading branch information
michaeloffner committed May 6, 2022
1 parent 1e4dbe9 commit 36a62cb
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 17 deletions.
35 changes: 20 additions & 15 deletions core/src/main/java/lucee/runtime/net/http/ReqRspUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -148,25 +148,30 @@ public static Cookie[] getCookies(HttpServletRequest req, Charset charset) {
}
}

String str = req.getHeader("Cookie");
if (str != null) {
try {
String[] arr = lucee.runtime.type.util.ListUtil.listToStringArray(str, ';'), tmp;
java.util.Map<String, Cookie> map = new HashMap<String, Cookie>();
Cookie c;
for (int i = 0; i < arr.length; i++) {
tmp = lucee.runtime.type.util.ListUtil.listToStringArray(arr[i], '=');
if (tmp.length > 0) {
c = ReqRspUtil.toCookie(dec(tmp[0], charset.name(), false), tmp.length > 1 ? dec(tmp[1], charset.name(), false) : "", null);
if (c != null) map.put(c.getName().toUpperCase(), c);
}
Enumeration<String> values = req.getHeaders("Cookie");
if (values != null) {
java.util.Map<String, Cookie> map = new HashMap<String, Cookie>();
if (cookies != null) {
for (Cookie cookie: cookies) {
map.put(cookie.getName().toUpperCase(), cookie);
}
}

if (cookies != null && map.size() > cookies.length) {
for (Cookie cookie: cookies) {
map.put(cookie.getName().toUpperCase(), cookie);
try {
String val;
while (values.hasMoreElements()) {
val = values.nextElement();
String[] arr = lucee.runtime.type.util.ListUtil.listToStringArray(val, ';'), tmp;
Cookie c;
for (int i = 0; i < arr.length; i++) {
tmp = lucee.runtime.type.util.ListUtil.listToStringArray(arr[i], '=');
if (tmp.length > 0) {
c = ReqRspUtil.toCookie(dec(tmp[0], charset.name(), false), tmp.length > 1 ? dec(tmp[1], charset.name(), false) : "", null);
if (c != null) map.put(c.getName().toUpperCase(), c);
}
}
}

cookies = map.values().toArray(new Cookie[map.size()]);
}
catch (Throwable t) {
Expand Down
2 changes: 1 addition & 1 deletion loader/build.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<project default="core" basedir="." name="Lucee" xmlns:artifact="antlib:org.apache.maven.artifact.ant">

<property name="version" value="5.3.9.139-SNAPSHOT"/>
<property name="version" value="5.3.9.140-SNAPSHOT"/>

<path id="maven-ant-tasks.classpath" path="../ant/lib/maven-ant-tasks-2.1.3.jar" />
<typedef resource="org/apache/maven/artifact/ant/antlib.xml"
Expand Down
2 changes: 1 addition & 1 deletion loader/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

<groupId>org.lucee</groupId>
<artifactId>lucee</artifactId>
<version>5.3.9.139-SNAPSHOT</version>
<version>5.3.9.140-SNAPSHOT</version>
<packaging>jar</packaging>

<name>Lucee Loader Build</name>
Expand Down

0 comments on commit 36a62cb

Please sign in to comment.