🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: news.software.readers
Article #243256

Re: Dialog (regex defect): Action rule using "Header" scans into body of post

#243256
From: VanguardLH
Date: Tue, 16 Nov 2010 23:34
94 lines
5960 bytes
Oliver Cromm wrote:

> * VanguardLH:
> 
> [...]
> 
>> I guess I'm still engrained in the old C programming style where \n
>> meant newline which could be \n or \r\n depending on the OS where the
>> end-of-line sequence was being added to the document.  So I figured on
>> Windows that \n meant the CR-LF sequence.  Well, according to the wiki
>> article at http://en.wikipedia.org/wiki/Newline, PCRE might still only
>> be using \n as the linefeed character.
>> 
>> I replace the $ trailing anchor (for end-of-line) with \r\n, as in:
>> 
>> ^Path: .+![^!]+\.othernsp\.com(!not-for-mail)?\r
>> 
>> This worked to match on just the trailing text in the same line as where
>> the Path header is defined.  I didn't even need the (?-s) operator
>> (which doesn't seem implemented in Dialog). 
> 
> It certainly is implemented. If, in your example, you change the regexp
> to the following, you should have no match (at least on the .41 version
> of Dialog):
> 
>  (?-s)^Path: .+report\.othernsp\.com$
> 
> Now change to (?s) or remove the switch, and you get a match, spanning
> two lines.
> 
> I forgot about (?-s) again, even though that's what I used before to
> test on single headers. However, I had no need of testing the end of
> line at the same time.
> 
> As for (?-m), it is the opposite of what I remembered: With (?-m), ^ and
> $ don't match lines any more, only the whole string, so that's what you
> don't want. The examples you gave should be OK with (?-s), maybe your
> tests were too complex to see it?

Yep, found out after some more testing that (?s) is the default.  From
what I've read:
 
. (dot)
Matches on any character EXCEPT \r and \n.

Not in Dialog.  I also found out the (?-s) would work but some of my
test cases still ended up including the linebreak.  For example, in
testing the Path header and allowing any host for a particular domain
for a node in the path:

(?-s)^Path: .+![^!]+\.alt\.net$

the [^!]+ was testing for one, or more, of any character OTHER than the
bang (since that is the node delimiter in the Path header).  Alas, it
included the linebreak so I ended up still doing a multi-line parse
despite using the (?-s) modifier.  

One solution was to use the lazy (non-greedy) version as [^!]+? (along
with the (?-s) modifier).  Another was to use [^!\r]+ since that also
excluded the carriage return character from a matching character.
However, since I was testing for the string to be at the end of the
line, I realized it really didn't matter what host was specified for the
injection domain and just changed it to:

(?-s)^Path: .+\.alt\.net$

Actually I used (as a baseline):

(?-s)^Path: .+\.alt\.net(!not-for-mail)$

According to Altopia's FAQ, their users are allowed to pre-load the Path
with their own domain, if they own one (or simply claim or think or
falsify that they one one).  The pre-loading goes before alt.net so this
rule still works.  The problem is Altopia does not enforce this syntax
and I have seen the poster's domain *after* the alt.net injection node
in the Path header; however, each time the poster stuck their domain
after the "not-for-email" string so the following works:

(?-s)^Path: .+\.alt\.net(!not-for-mail.*)?$

The (?-s) keeps the parsing to within the line.  If I get trickier with
the expression, like trying to re-add the [^!]+ to denote that any host
for a domain can be specified, as in [^!]+\.alt\.net then it doesn't
matter that I used (?-s) as the [^!]+ included the linebreak.  So I have
to instead use [^!\r]+ or [^!]+? even though I am also using (?-s).
That is probably because (?-s) is the DOTALL option and affect the dot
specifier but not when I'm using ?, +, or * on other characters.

Good thing Dialog comes with its own regex tester since sometimes it
just is not obvious why matches don't work or are more extensive than
desired.  I've also had to get used to testing on multiple lines of test
text with similar matching strings in the other lines just to be sure
that the parsing doesn't go beyond the one line where I really do want
to test.
Technical Details
Message-ID: <ibv4cj$rk7$1@news.albasani.net>
Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!illumos!news.pugleaf.net!.TX!archive.pugleaf.net!archive.newsdeef.eu!mbox2nntp-news.software.readers.20140922.mbox.gz!border1.nntp.ams3.giganews.com!border2.nntp.ams3.giganews.com!border2.nntp.ams2.giganews.com!border4.nntp.ams.giganews.com!border2.nntp.ams.giganews.com!nntp.giganews.com!news.mixmin.net!news.albasani.net!not-for-mail
References: <ibieuc$fa1$1@news.albasani.net> <4jnelelbf8ic.dlg@mid.crommatograph.info> <ibrutm$26h$1@news.albasani.net> <ibt23d$lq6$1@news.albasani.net> <MPG.274c0684271c22009896b2@news.individual.net> <ibuse3$g7b$1@news.albasani.net> <1le8kk22ig1xw$.dlg@mid.crommatograph.info>

Show Full Headers
Complete Article Headers
Message-ID: <ibv4cj$rk7$1@news.albasani.net>
Subject: Re: Dialog (regex defect): Action rule using "Header" scans into body of post
Date: Tue, 16 Nov 2010 17:34:23 -0600
From: VanguardLH <V@nguard.LH>
References: <ibieuc$fa1$1@news.albasani.net> <4jnelelbf8ic.dlg@mid.crommatograph.info> <ibrutm$26h$1@news.albasani.net> <ibt23d$lq6$1@news.albasani.net> <MPG.274c0684271c22009896b2@news.individual.net> <ibuse3$g7b$1@news.albasani.net> <1le8kk22ig1xw$.dlg@mid.crommatograph.info>
Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!illumos!news.pugleaf.net!.TX!archive.pugleaf.net!archive.newsdeef.eu!mbox2nntp-news.software.readers.20140922.mbox.gz!border1.nntp.ams3.giganews.com!border2.nntp.ams3.giganews.com!border2.nntp.ams2.giganews.com!border4.nntp.ams.giganews.com!border2.nntp.ams.giganews.com!nntp.giganews.com!news.mixmin.net!news.albasani.net!not-for-mail
Newsgroups: news.software.readers
Organization: 0.35MOA sniper at loose in Usenet
Lines: 94
Mime-Version: 1.0
Content-Type: text/plain; charset="us-ascii"
Content-Transfer-Encoding: 7bit
X-Trace: news.albasani.net
 8Hiu2x9hYdYALr1eEH+JSvyXIecWjmWXDv4y0NR1Pnw172p1MAE3VhLPY+eHQf3LL64eeLBvdUewTsje/IIiwOKfl7Evz7qc27jFXaHo5XJUl/tlmS0UuFLzz0tpiOCG
NNTP-Posting-Date: Tue, 16 Nov 2010 23:33:39 +0000 (UTC)
Keywords: VanguardLH VLH811
Cancel-Lock: sha1:3z1l3iIUuHVj4EfE/wz8N9BKFGM=
User-Agent: 40tude_Dialog/2.0.15.41
Injection-Info: news.albasani.net;
 logging-data="Ep+no1VagV0VtxZGRfrZ1vic/rHCZDd7BDuI9S/Q0fkU4r/QZX98jU94wFi3GTFeNWGRGNdftReF8MPjqeAr0Yv/18dViTt6PzBcbKgRJWiyPZwz24c5aW2vn6nPH2MK";
 mail-complaints-to="abuse@albasani.net"
X-MOTD: It is wiser to remain silent and let others ponder your ignorance than
 to speak and remove all doubt
X-Original-Bytes: 5758