【发布时间】:2023-02-24 16:16:33
【问题描述】:
使用 xidel,我从 SAMLResponse 中提取 //Assertion//Signature//KeyInfo//X509Certificate/text(),这是一个 X509 证书作为长 base64 字符串。
我想把这个字符串分成 64 个字符块
我试过 tokenize() 和 replace() 但我可以让这些工作,
replace() 似乎不允许我在替换字符串中使用换行符 \n:
echo "$SAMLRESPONSE" | base64 -D | xidel --xpath 'replace(//Assertion//Signature//KeyInfo//X509Certificate/text(),"(.{64})","$1\n")' -
**** Processing: stdin:/// ****
Error:
err:FORX0004: Invalid replacement: $1\n after $1\n
Possible backtrace:
$000000010203F668: perhaps TXQTermTryCatch + 222920 ? but unlikely
$0000000102068BBE: perhaps Q{http://www.w3.org/2005/xpath-functions}tokenize + 166350 ? but unlikely
$000000010203FF78: Q{http://www.w3.org/2005/xpath-functions}replace + 376
$0000000101FF853F: TXQTermNamedFunction + 767
$0000000101F71CE7: perhaps ? ? but unlikely
Call xidel with --trace-stack to get an actual backtrace
并且标记化会将整个匹配视为分隔符,分隔符不包含在输出中
echo "$SAMLRESPONSE" | base64 -D | xidel --xpath 'tokenize(//Assertion//Signature//KeyInfo//X509Certificate/text(),"(?:.{64})")' -
**** Processing: stdin:/// ****
XACcI5tcJbgsvr+ivGPos/WrhywkROwbEBh6OTNXTnaBiiIK
有没有办法在 XPath 中将字符串拆分为固定宽度的块?
【问题讨论】: