From 92dcae9723260a386bb5162edb9c015fd8fd669b Mon Sep 17 00:00:00 2001 From: dodmi <4572946+dodmi@users.noreply.github.com> Date: Sat, 4 Jan 2025 12:14:42 +0100 Subject: [PATCH] 2.x: Backport: Allow up to 3 levels of nested comments in ARH (#479) Backport of #466. --- modules/rfcParser.jsm.js | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/modules/rfcParser.jsm.js b/modules/rfcParser.jsm.js index 5566f45d..2addfcff 100644 --- a/modules/rfcParser.jsm.js +++ b/modules/rfcParser.jsm.js @@ -59,8 +59,13 @@ let rfcParser = (function() { RfcParserStd.FWS_op = `${RfcParserStd.FWS}?`; // Note: this is incomplete (obs-ctext is missing) RfcParserStd.ctext = "[!-'*-[\\]-~]"; - // Note: this is incomplete (comment is missing) - RfcParserStd.ccontent = `(?:${RfcParserStd.ctext}|${RfcParserStd.quoted_pair})`; + // Note: There is a recursion in ccontent/comment, which is not supported by the RegExp in JavaScript. + // We currently unroll it to support a depth of up to 3 comments. + RfcParserStd.ccontent_2 = `(?:${RfcParserStd.ctext}|${RfcParserStd.quoted_pair})`; + RfcParserStd.comment_2 = `\\((?:${RfcParserStd.FWS_op}${RfcParserStd.ccontent_2})*${RfcParserStd.FWS_op}\\)`; + RfcParserStd.ccontent_1 = `(?:${RfcParserStd.ctext}|${RfcParserStd.quoted_pair}|${RfcParserStd.comment_2})`; + RfcParserStd.comment_1 = `\\((?:${RfcParserStd.FWS_op}${RfcParserStd.ccontent_1})*${RfcParserStd.FWS_op}\\)`; + RfcParserStd.ccontent = `(?:${RfcParserStd.ctext}|${RfcParserStd.quoted_pair}|${RfcParserStd.comment_1})`; RfcParserStd.comment = `\\((?:${RfcParserStd.FWS_op}${RfcParserStd.ccontent})*${RfcParserStd.FWS_op}\\)`; RfcParserStd.CFWS = `(?:(?:(?:${RfcParserStd.FWS_op}${RfcParserStd.comment})+${RfcParserStd.FWS_op})|${RfcParserStd.FWS})`; // Note: helper only, not part of the RFC