Permalink
Browse files

fix header value parsing behavior for folded lines and make header va…

…lues always be arrays (of strings)
  • Loading branch information...
1 parent 8cdc54c commit 8e0e8e18030cb8a26913f09b5293fac6e7f5449c @mscdex committed Mar 10, 2013
Showing with 5 additions and 10 deletions.
  1. +1 −1 README.md
  2. +4 −9 lib/nntp.js
View
@@ -151,7 +151,7 @@ Methods
* **prev**(< _function_ >callback) - _(void)_ - Attempts to move to the previous article in the current newsgroup. `callback` has 3 parameters: < _Error_ >err, < _integer_ >articleNum, < _string_ >msgID.
-* **headers**([< _string_ >which, ]< _function_ >callback) - _(void)_ - Retrieves the headers of the current article if `which` is not given or for the article whose number or message ID is `what`. `callback` has 4 parameters: < _Error_ >err, < _integer_ >articleNum, < _string_ >msgID, < _object_ >headers. `headers` values containing an Array stores duplicate header values.
+* **headers**([< _string_ >which, ]< _function_ >callback) - _(void)_ - Retrieves the headers of the current article if `which` is not given or for the article whose number or message ID is `what`. `callback` has 4 parameters: < _Error_ >err, < _integer_ >articleNum, < _string_ >msgID, < _object_ >headers. `headers` values are always arrays (of strings).
* **body**([< _string_ >which, ]< _function_ >callback) - _(void)_ - Retrieves the body of the current article if `which` is not given or for the article whose number or message ID is `what`. `callback` has 4 parameters: < _Error_ >err, < _integer_ >articleNum, < _string_ >msgID, < _string_ >body. `body` is a binary string.
View
@@ -15,7 +15,6 @@ var tls = require('tls'),
reStat = /^(\d+)\s+(.+)$/,
reGroup = /^(\d+)\s+(\d+)\s+(\d+)\s/,
reHdr = /^([^:]+):\s?(.+)?$/,
- reHdrFold = /^\s+(.+)$/,
respsML = [100, 101, 215, 220, 221, 222, 224, 225, 230, 231],
respsHaveArgs = [111, 211, 220, 221, 222, 223, 401],
bytesCRLF = new Buffer([13, 10]),
@@ -382,19 +381,15 @@ NNTP.prototype.headers = function(what, cb) {
continue;
if (list[i][0] === '\t' || list[i][0] === ' ') {
// folded header content
- m = reHdrFold.exec(list[i]);
- if (Array.isArray(headers[h]))
- headers[h][headers[h].length - 1] += m[1];
- else
- headers[h] += m[1];
+ // RFC2822 says to just remove the CRLF and not the whitespace following
+ // it, so we follow the RFC and include the leading whitespace ...
+ headers[h][headers[h].length - 1] += m[1];
} else {
m = reHdr.exec(list[i]);
h = m[1].toLowerCase();
if (m[2]) {
if (headers[h] === undefined)
- headers[h] = m[2];
- else if (!Array.isArray(headers[h]))
- headers[h] = [headers[h], m[2]];
+ headers[h] = [m[2]];
else
headers[h].push(m[2]);
} else

0 comments on commit 8e0e8e1

Please sign in to comment.