rfc822-json
Version:
Parses an RFC-822 message stream (standard email) into JSON and returns a readable stream.
993 lines (961 loc) • 33.3 kB
HTML
<html lang="en">
<head>
<title>Code coverage report for lib/header-tokenizer.js</title>
<meta charset="utf-8">
<link rel="stylesheet" href="../prettify.css">
<style>
body, html {
margin:0; padding: 0;
}
body {
font-family: Helvetica Neue, Helvetica,Arial;
font-size: 10pt;
}
div.header, div.footer {
background: #eee;
padding: 1em;
}
div.header {
z-index: 100;
position: fixed;
top: 0;
border-bottom: 1px solid #666;
width: 100%;
}
div.footer {
border-top: 1px solid #666;
}
div.body {
margin-top: 10em;
}
div.meta {
font-size: 90%;
text-align: center;
}
h1, h2, h3 {
font-weight: normal;
}
h1 {
font-size: 12pt;
}
h2 {
font-size: 10pt;
}
pre {
font-family: Consolas, Menlo, Monaco, monospace;
margin: 0;
padding: 0;
line-height: 14px;
font-size: 14px;
-moz-tab-size: 2;
-o-tab-size: 2;
tab-size: 2;
}
div.path { font-size: 110%; }
div.path a:link, div.path a:visited { color: #000; }
table.coverage { border-collapse: collapse; margin:0; padding: 0 }
table.coverage td {
margin: 0;
padding: 0;
color: #111;
vertical-align: top;
}
table.coverage td.line-count {
width: 50px;
text-align: right;
padding-right: 5px;
}
table.coverage td.line-coverage {
color: #777 ;
text-align: right;
border-left: 1px solid #666;
border-right: 1px solid #666;
}
table.coverage td.text {
}
table.coverage td span.cline-any {
display: inline-block;
padding: 0 5px;
width: 40px;
}
table.coverage td span.cline-neutral {
background: #eee;
}
table.coverage td span.cline-yes {
background: #b5d592;
color: #999;
}
table.coverage td span.cline-no {
background: #fc8c84;
}
.cstat-yes { color: #111; }
.cstat-no { background: #fc8c84; color: #111; }
.fstat-no { background: #ffc520; color: #111 ; }
.cbranch-no { background: yellow ; color: #111; }
.missing-if-branch {
display: inline-block;
margin-right: 10px;
position: relative;
padding: 0 4px;
background: black;
color: yellow;
xtext-decoration: line-through;
}
.missing-if-branch .typ {
color: inherit ;
}
.entity, .metric { font-weight: bold; }
.metric { display: inline-block; border: 1px solid #333; padding: 0.3em; background: white; }
.metric small { font-size: 80%; font-weight: normal; color: #666; }
div.coverage-summary table { border-collapse: collapse; margin: 3em; font-size: 110%; }
div.coverage-summary td, div.coverage-summary table th { margin: 0; padding: 0.25em 1em; border-top: 1px solid #666; border-bottom: 1px solid #666; }
div.coverage-summary th { text-align: left; border: 1px solid #666; background: #eee; font-weight: normal; }
div.coverage-summary th.file { border-right: none ; }
div.coverage-summary th.pic { border-left: none ; text-align: right; }
div.coverage-summary th.pct { border-right: none ; }
div.coverage-summary th.abs { border-left: none ; text-align: right; }
div.coverage-summary td.pct { text-align: right; border-left: 1px solid #666; }
div.coverage-summary td.abs { text-align: right; font-size: 90%; color: #444; border-right: 1px solid #666; }
div.coverage-summary td.file { text-align: right; border-left: 1px solid #666; white-space: nowrap; }
div.coverage-summary td.pic { min-width: 120px ; }
div.coverage-summary a:link { text-decoration: none; color: #000; }
div.coverage-summary a:visited { text-decoration: none; color: #333; }
div.coverage-summary a:hover { text-decoration: underline; }
div.coverage-summary tfoot td { border-top: 1px solid #666; }
div.coverage-summary .yui3-datatable-sort-indicator, div.coverage-summary .dummy-sort-indicator {
height: 10px;
width: 7px;
display: inline-block;
margin-left: 0.5em;
}
div.coverage-summary .yui3-datatable-sort-indicator {
background: url("http://yui.yahooapis.com/3.6.0/build/datatable-sort/assets/skins/sam/sort-arrow-sprite.png") no-repeat scroll 0 0 transparent;
}
div.coverage-summary .yui3-datatable-sorted .yui3-datatable-sort-indicator {
background-position: 0 -20px;
}
div.coverage-summary .yui3-datatable-sorted-desc .yui3-datatable-sort-indicator {
background-position: 0 -10px;
}
.high { background: #b5d592 ; }
.medium { background: #ffe87c ; }
.low { background: #fc8c84 ; }
span.cover-fill, span.cover-empty {
display:inline-block;
border:1px solid #444;
background: white;
height: 12px;
}
span.cover-fill {
background: #ccc;
border-right: 1px solid #444;
}
span.cover-empty {
background: white;
border-left: none;
}
span.cover-full {
border-right: none ;
}
pre.prettyprint {
border: none ;
padding: 0 ;
margin: 0 ;
}
.com { color: #999 ; }
</style>
</head>
<body>
<div class="header high">
<h1>Code coverage report for <span class="entity">lib/header-tokenizer.js</span></h1>
<h2>
Statements: <span class="metric">94.68% <small>(89 / 94)</small></span>
Branches: <span class="metric">89.58% <small>(43 / 48)</small></span>
Functions: <span class="metric">100% <small>(6 / 6)</small></span>
Lines: <span class="metric">94.68% <small>(89 / 94)</small></span>
</h2>
<div class="path"><a href="../index.html">All files</a> » <a href="index.html">lib/</a> » header-tokenizer.js</div>
</div>
<div class="body">
<pre><table class="coverage">
<tr><td class="line-count">1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230</td><td class="line-coverage"><span class="cline-any cline-yes">1</span>
<span class="cline-any cline-yes">1</span>
<span class="cline-any cline-neutral"> </span>
<span class="cline-any cline-neutral"> </span>
<span class="cline-any cline-neutral"> </span>
<span class="cline-any cline-yes">1</span>
<span class="cline-any cline-neutral"> </span>
<span class="cline-any cline-yes">18</span>
<span class="cline-any cline-neutral"> </span>
<span class="cline-any cline-neutral"> </span>
<span class="cline-any cline-yes">18</span>
<span class="cline-any cline-yes">18</span>
<span class="cline-any cline-neutral"> </span>
<span class="cline-any cline-neutral"> </span>
<span class="cline-any cline-neutral"> </span>
<span class="cline-any cline-yes">18</span>
<span class="cline-any cline-yes">34</span>
<span class="cline-any cline-yes">1</span>
<span class="cline-any cline-neutral"> </span>
<span class="cline-any cline-neutral"> </span>
<span class="cline-any cline-neutral"> </span>
<span class="cline-any cline-neutral"> </span>
<span class="cline-any cline-neutral"> </span>
<span class="cline-any cline-yes">1</span>
<span class="cline-any cline-neutral"> </span>
<span class="cline-any cline-neutral"> </span>
<span class="cline-any cline-neutral"> </span>
<span class="cline-any cline-yes">1</span>
<span class="cline-any cline-neutral"> </span>
<span class="cline-any cline-neutral"> </span>
<span class="cline-any cline-neutral"> </span>
<span class="cline-any cline-neutral"> </span>
<span class="cline-any cline-neutral"> </span>
<span class="cline-any cline-neutral"> </span>
<span class="cline-any cline-neutral"> </span>
<span class="cline-any cline-yes">1</span>
<span class="cline-any cline-neutral"> </span>
<span class="cline-any cline-neutral"> </span>
<span class="cline-any cline-neutral"> </span>
<span class="cline-any cline-neutral"> </span>
<span class="cline-any cline-neutral"> </span>
<span class="cline-any cline-neutral"> </span>
<span class="cline-any cline-neutral"> </span>
<span class="cline-any cline-neutral"> </span>
<span class="cline-any cline-neutral"> </span>
<span class="cline-any cline-neutral"> </span>
<span class="cline-any cline-neutral"> </span>
<span class="cline-any cline-neutral"> </span>
<span class="cline-any cline-neutral"> </span>
<span class="cline-any cline-neutral"> </span>
<span class="cline-any cline-neutral"> </span>
<span class="cline-any cline-neutral"> </span>
<span class="cline-any cline-neutral"> </span>
<span class="cline-any cline-neutral"> </span>
<span class="cline-any cline-neutral"> </span>
<span class="cline-any cline-neutral"> </span>
<span class="cline-any cline-neutral"> </span>
<span class="cline-any cline-neutral"> </span>
<span class="cline-any cline-neutral"> </span>
<span class="cline-any cline-neutral"> </span>
<span class="cline-any cline-neutral"> </span>
<span class="cline-any cline-neutral"> </span>
<span class="cline-any cline-neutral"> </span>
<span class="cline-any cline-neutral"> </span>
<span class="cline-any cline-neutral"> </span>
<span class="cline-any cline-neutral"> </span>
<span class="cline-any cline-neutral"> </span>
<span class="cline-any cline-neutral"> </span>
<span class="cline-any cline-neutral"> </span>
<span class="cline-any cline-neutral"> </span>
<span class="cline-any cline-neutral"> </span>
<span class="cline-any cline-neutral"> </span>
<span class="cline-any cline-yes">1</span>
<span class="cline-any cline-yes">28</span>
<span class="cline-any cline-yes">28</span>
<span class="cline-any cline-yes">28</span>
<span class="cline-any cline-neutral"> </span>
<span class="cline-any cline-neutral"> </span>
<span class="cline-any cline-yes">1</span>
<span class="cline-any cline-neutral"> </span>
<span class="cline-any cline-neutral"> </span>
<span class="cline-any cline-neutral"> </span>
<span class="cline-any cline-neutral"> </span>
<span class="cline-any cline-neutral"> </span>
<span class="cline-any cline-neutral"> </span>
<span class="cline-any cline-neutral"> </span>
<span class="cline-any cline-neutral"> </span>
<span class="cline-any cline-neutral"> </span>
<span class="cline-any cline-neutral"> </span>
<span class="cline-any cline-yes">16</span>
<span class="cline-any cline-yes">7</span>
<span class="cline-any cline-yes">7</span>
<span class="cline-any cline-yes">7</span>
<span class="cline-any cline-yes">7</span>
<span class="cline-any cline-yes">7</span>
<span class="cline-any cline-neutral"> </span>
<span class="cline-any cline-neutral"> </span>
<span class="cline-any cline-neutral"> </span>
<span class="cline-any cline-neutral"> </span>
<span class="cline-any cline-neutral"> </span>
<span class="cline-any cline-yes">1</span>
<span class="cline-any cline-yes">28</span>
<span class="cline-any cline-yes">4784</span>
<span class="cline-any cline-neutral"> </span>
<span class="cline-any cline-neutral"> </span>
<span class="cline-any cline-neutral"> </span>
<span class="cline-any cline-neutral"> </span>
<span class="cline-any cline-neutral"> </span>
<span class="cline-any cline-neutral"> </span>
<span class="cline-any cline-neutral"> </span>
<span class="cline-any cline-neutral"> </span>
<span class="cline-any cline-neutral"> </span>
<span class="cline-any cline-yes">1</span>
<span class="cline-any cline-yes">4784</span>
<span class="cline-any cline-yes">4784</span>
<span class="cline-any cline-neutral"> </span>
<span class="cline-any cline-yes">748</span>
<span class="cline-any cline-neutral"> </span>
<span class="cline-any cline-neutral"> </span>
<span class="cline-any cline-yes">76</span>
<span class="cline-any cline-yes">76</span>
<span class="cline-any cline-yes">76</span>
<span class="cline-any cline-yes">672</span>
<span class="cline-any cline-neutral"> </span>
<span class="cline-any cline-yes">671</span>
<span class="cline-any cline-neutral"> </span>
<span class="cline-any cline-neutral"> </span>
<span class="cline-any cline-neutral"> </span>
<span class="cline-any cline-yes">1</span>
<span class="cline-any cline-neutral"> </span>
<span class="cline-any cline-yes">748</span>
<span class="cline-any cline-neutral"> </span>
<span class="cline-any cline-neutral"> </span>
<span class="cline-any cline-yes">3338</span>
<span class="cline-any cline-yes">2883</span>
<span class="cline-any cline-yes">455</span>
<span class="cline-any cline-yes">103</span>
<span class="cline-any cline-yes">352</span>
<span class="cline-any cline-yes">351</span>
<span class="cline-any cline-yes">351</span>
<span class="cline-any cline-neutral"> </span>
<span class="cline-any cline-yes">1</span>
<span class="cline-any cline-neutral"> </span>
<span class="cline-any cline-yes">3338</span>
<span class="cline-any cline-neutral"> </span>
<span class="cline-any cline-neutral"> </span>
<span class="cline-any cline-yes">482</span>
<span class="cline-any cline-yes">380</span>
<span class="cline-any cline-yes">380</span>
<span class="cline-any cline-yes">102</span>
<span class="cline-any cline-yes">1</span>
<span class="cline-any cline-yes">101</span>
<span class="cline-any cline-neutral"> </span>
<span class="cline-any cline-neutral"> </span>
<span class="cline-any cline-no"> </span>
<span class="cline-any cline-neutral"> </span>
<span class="cline-any cline-yes">482</span>
<span class="cline-any cline-neutral"> </span>
<span class="cline-any cline-neutral"> </span>
<span class="cline-any cline-yes">104</span>
<span class="cline-any cline-yes">100</span>
<span class="cline-any cline-yes">4</span>
<span class="cline-any cline-yes">3</span>
<span class="cline-any cline-yes">3</span>
<span class="cline-any cline-yes">1</span>
<span class="cline-any cline-neutral"> </span>
<span class="cline-any cline-yes">1</span>
<span class="cline-any cline-yes">1</span>
<span class="cline-any cline-yes">1</span>
<span class="cline-any cline-neutral"> </span>
<span class="cline-any cline-no"> </span>
<span class="cline-any cline-neutral"> </span>
<span class="cline-any cline-yes">104</span>
<span class="cline-any cline-neutral"> </span>
<span class="cline-any cline-neutral"> </span>
<span class="cline-any cline-yes">99</span>
<span class="cline-any cline-neutral"> </span>
<span class="cline-any cline-neutral"> </span>
<span class="cline-any cline-neutral"> </span>
<span class="cline-any cline-neutral"> </span>
<span class="cline-any cline-yes">62</span>
<span class="cline-any cline-yes">62</span>
<span class="cline-any cline-yes">62</span>
<span class="cline-any cline-yes">62</span>
<span class="cline-any cline-yes">37</span>
<span class="cline-any cline-yes">11</span>
<span class="cline-any cline-yes">26</span>
<span class="cline-any cline-neutral"> </span>
<span class="cline-any cline-yes">26</span>
<span class="cline-any cline-yes">26</span>
<span class="cline-any cline-neutral"> </span>
<span class="cline-any cline-no"> </span>
<span class="cline-any cline-neutral"> </span>
<span class="cline-any cline-yes">99</span>
<span class="cline-any cline-neutral"> </span>
<span class="cline-any cline-neutral"> </span>
<span class="cline-any cline-yes">11</span>
<span class="cline-any cline-neutral"> </span>
<span class="cline-any cline-neutral"> </span>
<span class="cline-any cline-neutral"> </span>
<span class="cline-any cline-neutral"> </span>
<span class="cline-any cline-yes">9</span>
<span class="cline-any cline-yes">9</span>
<span class="cline-any cline-yes">9</span>
<span class="cline-any cline-yes">9</span>
<span class="cline-any cline-yes">2</span>
<span class="cline-any cline-yes">1</span>
<span class="cline-any cline-yes">1</span>
<span class="cline-any cline-yes">1</span>
<span class="cline-any cline-neutral"> </span>
<span class="cline-any cline-yes">1</span>
<span class="cline-any cline-yes">1</span>
<span class="cline-any cline-yes">1</span>
<span class="cline-any cline-neutral"> </span>
<span class="cline-any cline-no"> </span>
<span class="cline-any cline-neutral"> </span>
<span class="cline-any cline-yes">11</span>
<span class="cline-any cline-neutral"> </span>
<span class="cline-any cline-neutral"> </span>
<span class="cline-any cline-neutral"> </span>
<span class="cline-any cline-yes">2</span>
<span class="cline-any cline-neutral"> </span>
<span class="cline-any cline-neutral"> </span>
<span class="cline-any cline-neutral"> </span>
<span class="cline-any cline-no"> </span>
<span class="cline-any cline-neutral"> </span>
<span class="cline-any cline-neutral"> </span>
<span class="cline-any cline-neutral"> </span>
<span class="cline-any cline-yes">1</span>
<span class="cline-any cline-neutral"> </span></td><td class="text"><pre class="prettyprint lang-js">var Stream = require('stream');
var util = require('util');
// Creates a reusable tokenizer which inherits from
// the Stream module.
function HeaderTokenizer() {
// Call the Stream.Transform constructor
Stream.Transform.call(this);
// Initialize state
this.state = this.states.FIELD_NAME;
this.currentToken = {type: 'field_name', value: ""};
// If someone attaches a new event listener for the 'done' event after
// we are already in the DONE state, then just re-fire the event.
this.on('newListener', function(name, listener) {
if (name === 'done' && this.state === this.states.DONE) {
listener();
}
});
}
// Set up the inheritance
util.inherits(HeaderTokenizer, Stream.Transform);
// Helper object to hold the regular expressions for matching various
// character types.
HeaderTokenizer.prototype.charTypes = {
colon: /\:/,
newline: /\n/,
whitespace: /\s/,
carraigeReturn: /\r/,
printableAscii: /[\x21-\x7e]/
};
HeaderTokenizer.prototype.states = {
// While processing a field name the tokenizer is in this state.
FIELD_NAME: 'FIELD_NAME',
// While processing printable characters in the field body the tokenizer
// is in this state.
FIELD_BODY: 'FIELD_BODY',
// While processing whitespace characters in the field body the
// tokenizer is in this state. All consecutive whitespace characters are
// collapsed into a single space.
WHITESPACE: 'WHITESPACE',
// While processing a <CR> in the field body the tokenizer is in this
// state.
CARRAIGE_RETURN: 'CARRAIGE_RETURN',
// While processing stuff after a <CR><LF> the tokenizer is in this
// state. Note that header field bodies are allowed to "fold," meaning
// that they can carry onto multiple lines as long as the "folded over"
// portion is indented with at least one linear white space character.
CRLF: 'CRLF',
// While processing stuff after a <CR><LF><CR> the tokenizer is in this
// state. Significant because the tokenizer expects a <LF> and will emit
// an error if it receives anything else.
CRLF_CR: 'CRLF_CR',
// After consuming an empty line, the tokenizer emits a "done" event and
// transitions to this trap state. TODO: deprecate the "done" event
// since the message parser will probably never even send the header
// tokenier the require CRLFCRLF characters required to get to this done
// state.
DONE: 'DONE'
};
// Implements the Stream.Transform._transform method.
HeaderTokenizer.prototype._transform = function(chunk, encoding, callback) {
var str = chunk.toString('binary');
this.tokenize(str);
callback();
};
HeaderTokenizer.prototype._flush = function(callback) {
// Assert: we are done consuming the readable stream. Emit the current
// token. If we have already entered the DONE state then do not emit
// anything. We do this check because there are two cases when we want
// to emit the 'done' event:
// 1. After encountering <CR><LF><CR><LF> sequence in an email message.
// When this happens, the HeaderTokenizer immediately enters the DONE
// state.
// 2. After encountering the end of a stream in an email message which
// contained no message body (and thus potentially no <CR><LF><CR><LF>
// sequence).
if (this.state !== this.states.DONE) {
this.state = this.states.DONE;
this.currentToken.value = this.currentToken.value.trim();
this.emit('token', this.currentToken);
this.emit('done');
callback();
}
};
// The tokenize function simply takes in a string and feeds each character
// to the HeaderTokenizer#receiveChar function.
HeaderTokenizer.prototype.tokenize = function(str) {
for (var i = 0; i < str.length; i++) {
this.receiveChar(str[i]);
}
};
// This function is the heart of the HeaderTokenizer class. It consumes
// the characters of an email message sequentially, emitting
// "token" events when it has finished tokenizing header field names and
// header field bodies. The "token" events have a
// header token object of the form `{type:'field_body', value:'blah'}` as
// the argument for their listener functions.
HeaderTokenizer.prototype.receiveChar = function(ch) {
var states = this.states; // Cache the states
switch(this.state) {
case this.states.FIELD_NAME:
if (this.charTypes.colon.test(ch)) {
// Colon delimits fieldName:fieldBody. Emit the current
// field name token and set up the new field body token
this.emit('token', this.currentToken);
this.currentToken = {type: 'field_body', value: ""};
this.state = states.FIELD_BODY;
} else if (this.charTypes.printableAscii.test(ch)) {
// Append to the current field name
this.currentToken.value += ch;
} else {
// Whitespace, or other non-printable ascii characters are
// not allowed in the field names
this.emit('error', new Error('Unexpected character "' + ch + '" while parsing field name.'));
}
break;
case this.states.FIELD_BODY:
if (this.charTypes.printableAscii.test(ch)) {
this.currentToken.value += ch;
} else if (this.charTypes.carraigeReturn.test(ch)) {
this.state = states.CARRAIGE_RETURN;
} else if (this.charTypes.whitespace.test(ch)) {
this.currentToken.value += " ";
this.state = states.WHITESPACE;
} else {
this.emit('error', new Error('Unexpected character "' + ch + '" while parsing field body.'));
}
break;
case this.states.WHITESPACE:
if (this.charTypes.printableAscii.test(ch)) {
this.currentToken.value += ch;
this.state = states.FIELD_BODY;
} else if (this.charTypes.carraigeReturn.test(ch)) {
this.state = states.CARRAIGE_RETURN;
} else <span class="missing-if-branch" title="else path not taken"" >E</span>if (this.charTypes.whitespace.test(ch)) {
// Do nothing; just eat more whitespace
} else {
<span class="cstat-no" title="statement not covered" > this.emit('error', new Error('Unexpected character "' + ch + '" found while parsing field body.'));</span>
}
break;
case this.states.CARRAIGE_RETURN:
if (this.charTypes.newline.test(ch)) {
this.state = states.CRLF;
} else if (this.charTypes.whitespace.test(ch)) {
this.currentToken.value += " ";
this.state = states.WHITESPACE;
} else <span class="missing-if-branch" title="else path not taken"" >E</span>if (this.charTypes.printableAscii.test(ch)) {
// Push a space to account for the CR we read previously
this.currentToken.value += " ";
this.currentToken.value += ch;
this.state = states.FIELD_BODY;
} else {
<span class="cstat-no" title="statement not covered" > this.emit('error', new Error('Unexpected character "' + ch + '" found while parsing field body.'));</span>
}
break;
case this.states.CRLF:
if (this.charTypes.printableAscii.test(ch)) {
// A printable character on the very next line means we just
// finished the field body of one header and are now parsing
// the field name of a new header. Trim any whitespace from
// the beginning/end of the field body and emit.
this.currentToken.value = this.currentToken.value.trim();
this.emit('token', this.currentToken);
this.state = states.FIELD_NAME;
this.currentToken = {type: 'field_name', value: ch};
} else if (this.charTypes.carraigeReturn.test(ch)) {
this.state = states.CRLF_CR;
} else <span class="missing-if-branch" title="else path not taken"" >E</span>if (this.charTypes.whitespace.test(ch)) {
// This is just field body folding
this.currentToken.value += " ";
this.state = states.WHITESPACE;
} else {
<span class="cstat-no" title="statement not covered" > this.emit('error', new Error('Unexpected character "' + ch + '" found while parsing field body.'));</span>
}
break;
case this.states.CRLF_CR:
if (this.charTypes.newline.test(ch)) {
// We have already seen <CR><LF><CR>. Another <LF> means
// this is the empty line separating header fields from the
// message body. Emit the final field body token and a done
// event.
this.currentToken.value = this.currentToken.value.trim();
this.emit('token', this.currentToken);
this.emit('done');
this.state = states.DONE;
} else if (this.charTypes.whitespace.test(ch)) {
this.currentToken.value += " ";
this.state = states.WHITESPACE;
} else <span class="missing-if-branch" title="else path not taken"" >E</span>if (this.charTypes.printableAscii.test(ch)) {
// This is just field body folding
this.currentToken.value += " ";
this.currentToken.value += ch;
this.state = states.FIELD_BODY;
} else {
<span class="cstat-no" title="statement not covered" > this.emit('error', new Error('Unexpected character "' + ch + '" found while parsing field body.'));</span>
}
break;
case this.states.DONE:
// Trap state
break;
<span class="branch-7 cbranch-no" title="branch not covered" > default:</span>
// Should never get here, but in case we do...
<span class="cstat-no" title="statement not covered" > this.emit('error', new Error('Unknown state "' + this.state + '"'));</span>
}
};
module.exports = HeaderTokenizer;
</pre></td></tr>
</table></pre>
</div>
<div class="footer">
<div class="meta">Generated by <a href="http://istanbul-js.org/" target="_blank">istanbul</a> at Fri Jan 10 2014 22:59:04 GMT-0800 (PST)</div>
</div>
<script src="../prettify.js"></script>
<script src="http://yui.yahooapis.com/3.6.0/build/yui/yui-min.js"></script>
<script>
YUI().use('datatable', function (Y) {
var formatters = {
pct: function (o) {
o.className += o.record.get('classes')[o.column.key];
try {
return o.value.toFixed(2) + '%';
} catch (ex) { return o.value + '%'; }
},
html: function (o) {
o.className += o.record.get('classes')[o.column.key];
return o.record.get(o.column.key + '_html');
}
},
defaultFormatter = function (o) {
o.className += o.record.get('classes')[o.column.key];
return o.value;
};
function getColumns(theadNode) {
var colNodes = theadNode.all('tr th'),
cols = [],
col;
colNodes.each(function (colNode) {
col = {
key: colNode.getAttribute('data-col'),
label: colNode.get('innerHTML') || ' ',
sortable: !colNode.getAttribute('data-nosort'),
className: colNode.getAttribute('class'),
type: colNode.getAttribute('data-type'),
allowHTML: colNode.getAttribute('data-html') === 'true' || colNode.getAttribute('data-fmt') === 'html'
};
col.formatter = formatters[colNode.getAttribute('data-fmt')] || defaultFormatter;
cols.push(col);
});
return cols;
}
function getRowData(trNode, cols) {
var tdNodes = trNode.all('td'),
i,
row = { classes: {} },
node,
name;
for (i = 0; i < cols.length; i += 1) {
name = cols[i].key;
node = tdNodes.item(i);
row[name] = node.getAttribute('data-value') || node.get('innerHTML');
row[name + '_html'] = node.get('innerHTML');
row.classes[name] = node.getAttribute('class');
//Y.log('Name: ' + name + '; Value: ' + row[name]);
if (cols[i].type === 'number') { row[name] = row[name] * 1; }
}
//Y.log(row);
return row;
}
function getData(tbodyNode, cols) {
var data = [];
tbodyNode.all('tr').each(function (trNode) {
data.push(getRowData(trNode, cols));
});
return data;
}
function replaceTable(node) {
if (!node) { return; }
var cols = getColumns(node.one('thead')),
data = getData(node.one('tbody'), cols),
table,
parent = node.get('parentNode');
table = new Y.DataTable({
columns: cols,
data: data,
sortBy: 'file'
});
parent.set('innerHTML', '');
table.render(parent);
}
Y.on('domready', function () {
replaceTable(Y.one('div.coverage-summary table'));
if (typeof prettyPrint === 'function') {
prettyPrint();
}
});
});
</script>
</body>
</html>