我需要转换一段代码,这样它才能在Lucee上工作。
这是CF中的工作代码,它在Lucee中不起作用:
if(structKeyExists(response.responseheader, 'Set-Cookie')) {
var refind = refindNoCase("JSESSIONID=([\w\d]+);", response.responseheader['Set-Cookie'], 1, true);
if(structkeyexists(refind, 'match') and isArray(refind.match) and arraylen(refind.match) == 2) {
variables.sessionId = refind.match[2];
}
}Response.responseHeader‘’Set Cookie‘是一个数组:
Array
1
string JSESSIONID=CC319C9B3CFA261A72724EAEB36B5C2D; HttpOnly=false; Secure; SameSite=None在CF中,variables.sessionId = CC319C9B3CFA261A72724EAEB36B5C2D的输出,这正是我需要的。
Lucee抛出一个错误:无法将复杂对象类型数组转换为字符串,因此我将代码更改为:
if(structKeyExists(response.responseheader, 'Set-Cookie')) {
var refind = refindNoCase("JSESSIONID=([\w\d]+);", serialize(response.responseheader['Set-Cookie']), 1, true);
if(structkeyexists(refind, 'match') and isArray(refind.match) and arraylen(refind.match) == 2) {
variables.sessionId = refind.match[2];
}
}但现在variables.sessionId持有“JSESSIONID=CC319C9B3CFA261A72724EAEB36B5C2D”
这怎么可能不一样?我还尝试在https://regex101.com/r/cO8lqs/4上使用硬编码字符串,只给我“CC319C9B3CFA261A72724EAEB36B5C2D”),在https://docs.lucee.org/reference/functions/refindnocase.html上运行代码片段时,给出“JSESSIONID=CC319C9B3CFA261A72724EAEB36B5C2D”和“JSESSIONID=CC319C9B3CFA261A72724EAEB36B5C2D”完全相同的字符串。我如何在Lucee得到我所需要的,只有'CC319C9B3CFA261A72724EAEB36B5C2D'?而且它也需要在CF上运行,因为我们的生产服务器仍然在ACF上。
发布于 2021-01-14 15:51:35
这并不能解释为什么Lucee会有所不同--这可能是https://luceeserver.atlassian.net/browse/LDEV-2333?oldIssueView=true最近修复的错误的结果--但这是对您的问题的回答:
“我如何在Lucee获得我所需要的,只有'CC319C9B3CFA261A72724EAEB36B5C2D'?而且它也需要在CF上运行,因为我们的生产服务器仍然在ACF上。”
...that为您提供了使用Adobe所需的结果,即使用variables.sessionId = listFirst(listLast(refind.match[2],'='),';');
独立示例(var被删除,因为它不在这里的函数中)=
<cfscript>
response.responseheader['Set-Cookie'] = ["JSESSIONID=CC319C9B3CFA261A72724EAEB36B5C2D; HttpOnly=false; Secure; SameSite=None"];
if(structKeyExists(response.responseheader, 'Set-Cookie')) {
refind = refindNoCase("JSESSIONID=([\w\d]+);", response.responseheader['Set-Cookie'][1], 1, true);
if(structkeyexists(refind, 'match') and isArray(refind.match) and arraylen(refind.match) == 2) {
variables.sessionId = listFirst(listLast(refind.match[2],'='),';');
}
}
writeDump(variables.sessionId);
</cfscript>https://stackoverflow.com/questions/65721123
复制相似问题