"Florian Gross" <flgr / ccan.de> responded
> Dave Burt wrote:
>
>> Hi Florian,
>
> Moin Dave.
>
>> As always, I'm amazed by your concise code. But your solution seems to be 
>> failing a bunch of my tests (and not just by chopping lines early, which 
>> is allowed):
>
> Thanks, I'll have a look.
>
>> encoding:
>> - escapes mid-line whitespace
>
> I'm not sure I get this. Am I incorrectly escaping mid-line whitespace or 
> am I incorrectly not escaping it? And what is mid-line whitespace?

Tabs and spaces that are followed by something printable on the same line 
should not be escaped; see the following:

  5) Failure:
test_encode_12(TC_QuotedPrintable) [(eval):2]:
<"=3D=3D=3D 
=\r\n                =20\r\n"> expected but was
<"=3D=3D=3D=20 =20 =20 =20 =20 =20 =20 =20 =20 =20 =20 =20 =20 =20 =20 =20 
=\r\n=20 =20 =20 =20 =20 =20 =20 =20 =20 =20 =20 =20 =20 =20 =20 =20 =20 =20 
=20 =20 =20 =20 =20 =20 =20 =20\r\n">.

>> - escapes '~'
>
> Heh, classic off-by-one. Easily fixed by changing the Regexp. See source 
> below.

Too easy :)

>> - allows too-long lines (my tests saw up to 104 characters on a line)
>
> Any hints on when this is happening? I can't see why and when this would 
> happen.

test_encode_12 also demonstrates this. I fixed it by changing 
/[\t ](?:[\v\t ]|$)../ to /[\t ]$../.
This (obviously) fixes the mid-line whitespace as well.

>> - allows unescaped whitespace on the end of a line (as long as it's 
>> preceded by escaped whitespace)
>
> Fixed. See code below.
>
>> decoding:
>> - doesn't ignore trailing literal whitespace
>
> Well, I don't think that's much of an issue as I'm not sure when trailing 
> whitespace would be prepended to lines, but I've fixed it anyway.

It's not mentioned in the quiz question, although you can infer that it is 
illegal from the quiz question. The idea is that if there is trailing 
whitespace, it has been added in transit and should be removed (it's not 
actually part of the data that was encoded).

Also, this, on line 10: "char[0 ... -1] + ...", seems redundant - with char 
as a one-character match, it's an empty string.

> Here's the new code:
>
>>   <snip>
>
> I'll repost the full source when I've sorted out that other problem as 
> well.

Cheers,
Dave