On 04/07/2011 02:50 PM, Stephen wrote:
Hi
Thanks for looking into this, Paolo, and for showing how the code could
best be tested.
I have been away with work for a week with work and hence the delay
responding.
I've applied your patch to latest GST from Git today (3.2.90-3cd3a73),
however there is still an error.
~/gst-devel $ ./sitemonitor.st
Try this one. It works on the full moodle.org site, not just my toy
testcase.
(I wasn't too sure of the other patch, which is why I hadn't pushed it yet).
Paolo
>From 8a702bba7b36dbe362057dbca0bfa1f4a78436fd Mon Sep 17 00:00:00 2001
From: Paolo Bonzini <[email protected]>
Date: Tue, 29 Mar 2011 14:46:31 +0200
Subject: [PATCH] rfc822: fix parsing of empty fields
packages/net:
2011-03-29 Paolo Bonzini <[email protected]>
* MIME.st: Do not fail on empty fields like "Expires: \r\n".
---
packages/net/ChangeLog | 4 ++++
packages/net/MIME.st | 42 +++++++++++++++++++++++++++---------------
2 files changed, 31 insertions(+), 15 deletions(-)
diff --git a/packages/net/ChangeLog b/packages/net/ChangeLog
index 1e4f1f8..6b67427 100644
--- a/packages/net/ChangeLog
+++ b/packages/net/ChangeLog
@@ -1,5 +1,9 @@
2011-03-29 Paolo Bonzini <[email protected]>
+ * MIME.st: Do not fail on empty fields like "Expires: \r\n".
+
+2011-03-29 Paolo Bonzini <[email protected]>
+
* HTTP.st: Accept end-of-file where a chunked encoding header
should have been.
diff --git a/packages/net/MIME.st b/packages/net/MIME.st
index 0460bc2..a948293 100644
--- a/packages/net/MIME.st
+++ b/packages/net/MIME.st
@@ -223,8 +223,8 @@ Object subclass: SimpleScanner [
#(32 9) includes: c asInteger].
self initClassificationTableWith: CRLFMask
when: [:c | c == Character cr or: [c == Character nl]].
- self initClassificationTableWith: EndOfLineMask
- when: [:c | c == Character cr]
+ "self initClassificationTableWith: EndOfLineMask
+ when: [:c | c == Character cr]"
]
SimpleScanner class >> initClassificationTableWith: mask when: aBlock [
@@ -588,6 +588,7 @@ Object subclass: SimpleScanner [
<category: 'stream interface -- reading'>
lookahead notNil ifTrue: [^lookahead].
self atEnd ifTrue: [^nil].
+ hereChar := nil.
lookahead := source next.
^lookahead
]
@@ -1142,11 +1143,9 @@ MessageElement subclass: MimeEntity [
parseFieldsFrom: rfc822Stream [
<category: 'parsing'>
- | cr nl |
-
- [(cr := rfc822Stream peekFor: Character cr)
- | (nl := rfc822Stream peekFor: Character nl)]
- whileFalse: [self parseFieldFrom: rfc822Stream]
+ [rfc822Stream atEndOfLine]
+ whileFalse: [self parseFieldFrom: rfc822Stream].
+ rfc822Stream next; skipEndOfLine
]
parseMultipartBodyFrom: rfc822Stream [
@@ -2695,16 +2694,29 @@ MailScanner subclass: RFC822Scanner [
^token
]
- scanEndOfLine [
- "Note: this will work only for RFC822 but not for HTTP. Needs more
design work"
+ atEndOfLine [
+ <category: 'multi-character scans'>
+ self peek.
+ ^(self classificationMaskFor: lookahead) anyMask: CRLFMask
+ ]
+ skipEndOfLine [
<category: 'multi-character scans'>
- (self matchCharacterType: CRLFMask) ifFalse: [^self].
hereChar == Character nl
ifFalse:
[(source peekFor: Character nl)
- ifFalse: [^self]
+ ifFalse: [^false]
ifTrue: [self sourceTrailNextPut: Character nl]].
+ ^true
+ ]
+
+ scanEndOfLine [
+ "Note: this will work only for RFC822 but not for HTTP. Needs more
design work"
+
+ <category: 'multi-character scans'>
+ "Called after #step, so no need to peek to set the CRLFMask."
+ (self matchCharacterType: CRLFMask) ifFalse: [^false].
+ self skipEndOfLine ifFalse: [^self].
self shouldFoldLine
ifTrue:
[self hereChar: Character space.
@@ -2770,6 +2782,7 @@ MailScanner subclass: RFC822Scanner [
"RFC822: text = <Any CHAR, including bare CR & bare LF, but not
including CRLF. This is a 'catchall' category and cannot be tokenized. Text is
used only to read values of unstructured fields"
<category: 'multi-character scans'>
+ (self matchCharacterType: EndOfLineMask) ifTrue: [^String new].
^self scanUntil: [self matchCharacterType: CRLFMask]
]
@@ -2863,14 +2876,13 @@ MailScanner subclass: RFC822Scanner [
<category: 'private'>
| char |
self atEnd ifTrue: [^false].
- char := source next.
+ char := source peek.
^((self classificationMaskFor: char) anyMask: WhiteSpaceMask)
ifFalse:
- [lookahead := char.
- self resetToken.
+ [self resetToken; peek.
false]
ifTrue:
- [self sourceTrailNextPut: char.
+ [self sourceTrailNextPut: source next.
true]
]
--
1.7.4
_______________________________________________
help-smalltalk mailing list
[email protected]
http://lists.gnu.org/mailman/listinfo/help-smalltalk