Skip to content

Commit

Permalink
fix header value parsing behavior for folded lines and make header va…
Browse files Browse the repository at this point in the history
…lues always be arrays (of strings)
  • Loading branch information
mscdex committed Mar 10, 2013
1 parent 8cdc54c commit 8e0e8e1
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 10 deletions.
2 changes: 1 addition & 1 deletion README.md
Expand Up @@ -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.

Expand Down
13 changes: 4 additions & 9 deletions lib/nntp.js
Expand Up @@ -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]),
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 8e0e8e1

Please sign in to comment.