Subject: [sup-talk] Bug reading/writing contacts with \" in them

From: Ico <[email-masked]>
Date: Mon, 24 Jan 2011 06:20:47 +0100

Hi all,

I just found out about Sup yesterday, great stuff, thanks for that to all
involved with development!

I did run into a small bug yesterday though. I was able to analyze it a bit,
but my Ruby is not good enough to propose a solid fix. 

The problem occurs when contacts have a certain combination of backslashes and
quotes in them. I 'imported' my mutt aliases with a simple script converting
the format (too bad it is *almost* the same but not quite), and one of the
contacts looked like this:

  somename: \"Some, Name\" <[email-masked]>

It seems there is a problem somewhere with parsing and writing out the backslashes, which
get escaped each time sup saves the contact list, doubling the number of backslashes each time.

  somename: Some, Name\\ <[email-masked]>
  somename: Some, Name\\\\ <[email-masked]>
  somename: Some, Name\\\\\\\\ <[email-masked]>

and so on.

I first got a hint something was wrong when I noticed that sup was starting up slower
and slower each time, and took over 10 minutes after a few tries. It seems that the regexp
at person.rb:79 

         when /(.+?) ((\S+?)@\S+) \3/

goes haywire backtracking through all the backslashes, I guess the first .+?
probably uses exponential time when trying to match the huge number of \'s

Anyway, I did some quick trials to find where exaclty the bug is, but I
couldn't come up with the proper fix right away. My problem has of course gone
away by just removing the backslashes from the contacts file, but I hope
somebody with more ruby-sense is willing to look into this one.

Thanks,

Ico

-- 
:wq
^X^Cy^K^X^C^C^C^C
_______________________________________________
sup-talk mailing list
[email-masked]
http://rubyforge.org/mailman/listinfo/sup-talk

---

From: Michael Stapelberg <[email-masked]>
Date: Mon, 24 Jan 2011 19:20:13 +0100

Hi Ico,

>   somename: \"Some, Name\" <[email-masked]>
As discussed on IRC, I’ve made the following findings:

 • Some combinations of email addresses (phrase + addr-spec in RFC822
   terminology) need to be escaped, for example when they contain a comma or a
   quote.
 • This escaping happens in Person#full_address by using @name.inspect
 • Person#full_address also is used when saving contacts back to contacts.txt
 • Person#initialize partly strips the quotes (line 10/11), but does not handle
   backslashes.

Attached is a patch which fixes the issue. Input like "Rob, Post\" will first
be turned into "Rob, Post\\" when initially escaping, but will then stay "Rob,
Post\\" (no more exploding backslashes).

Best regards,
Michael
_______________________________________________
Sup-devel mailing list
[email-masked]
http://rubyforge.org/mailman/listinfo/sup-devel