| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -159,9 +159,26 @@ function decodeMessage(msg){ | |||
| 159 | 159 | break; | |
| 160 | 160 | } | |
| 161 | 161 | if (key == null && value == null && chr == ':'){ | |
| 162 | - data = msg.substr(i + 1); | ||
| 162 | + data = msg.substr(i + 1); | ||
| 163 | 163 | break; | |
| 164 | 164 | } | |
| 165 | + if (chr === "\n"){ | ||
| 166 | + anns[key] = value; | ||
| 167 | + key = value = undefined; | ||
| 168 | + continue; | ||
| 169 | + } | ||
| 170 | + if (key === undefined){ | ||
| 171 | + key = chr; | ||
| 172 | + continue; | ||
| 173 | + } | ||
| 174 | + if (value === undefined && chr == ':'){ | ||
| 175 | + value = ''; | ||
| 176 | + continue; | ||
| 177 | + } | ||
| 178 | + if (value !== undefined) | ||
| 179 | + value += chr; | ||
| 180 | + else | ||
| 181 | + key += chr; | ||
| 165 | 182 | } | |
| 166 | 183 | return [data, anns]; | |
| 167 | 184 | } | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -182,6 +182,29 @@ module.exports = { | |||
| 182 | 182 | 'test message encoding with annotations': function(assert){ | |
| 183 | 183 | assert.ok(encodeMessage('', {j: null}) === 'j\n:'); | |
| 184 | 184 | assert.ok(encodeMessage('Test', {j: null, re: 'test'}) === 'j\nre:test\n:Test'); | |
| 185 | + }, | ||
| 186 | + | ||
| 187 | + 'test message decoding without annotations': function(assert){ | ||
| 188 | + var decoded1 = decodeMessage(':') | ||
| 189 | + , decoded2 = decodeMessage(':Testing'); | ||
| 190 | + | ||
| 191 | + assert.ok(decoded1[0] === ''); | ||
| 192 | + assert.ok(Object.keys(decoded1[1]).length === 0); | ||
| 193 | + | ||
| 194 | + assert.ok(decoded2[0] === 'Testing'); | ||
| 195 | + assert.ok(Object.keys(decoded2[1]).length === 0); | ||
| 196 | + }, | ||
| 197 | + | ||
| 198 | + 'test message decoding with annotations': function(assert){ | ||
| 199 | + var decoded1 = decodeMessage('j\n:') | ||
| 200 | + , decoded2 = decodeMessage('j\nre:test\n:Test'); | ||
| 201 | + | ||
| 202 | + assert.ok(decoded1[0] === ''); | ||
| 203 | + assert.ok('j' in decoded1[1]); | ||
| 204 | + | ||
| 205 | + assert.ok(decoded2[0] === 'Test'); | ||
| 206 | + assert.ok('j' in decoded2[1]); | ||
| 207 | + assert.ok(decoded2[1].re === 'test'); | ||
| 185 | 208 | } | |
| 186 | 209 | ||
| 187 | 210 | }; | |
| Back | FazBrowse Home | New Git URL |
0 commit comments