Lucee 中的正则表达式 refindNoCase

问题描述

我需要转换一段代码才能在 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']),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' 两者都使用完全相同的字符串运行。 我将如何在 lucee 获得我需要的东西,只有“CC319C9B3CFA261A72724EAEB36B5C2D”? 而且它也需要在 CF 上运行,因为我们的生产服务器仍然在 ACF 上..

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)