Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

_parseIndented() crashes when there is no trailing newline #63

Closed
wants to merge 2 commits into from

2 participants

@substack

Given test output like:

not ok 1 Error: beep boop
  ---
    stack:
      - rawr
      - dinosaurs
  ...

except without a trailing newline crashes _paseIndented() because this._indent has undefined elements. This patch and test add a check for undefined elements to fix this crashing behavior.

@isaacs isaacs closed this pull request from a commit
@substack substack Fix #63 Fix crash when there is no trailing newline
failing test for undefined line causing line.trim() to throw

fix the undefined indent test
cc6e4d0
@isaacs isaacs closed this in cc6e4d0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
This page is out of date. Refresh to see the latest.
Showing with 30 additions and 1 deletion.
  1. +3 −1 lib/tap-consumer.js
  2. +27 −0 test/undefined_indented.js
View
4 lib/tap-consumer.js
@@ -215,7 +215,9 @@ TapConsumer.prototype._parseIndented = function () {
//console.error(ind, this._indent)
for (var i = 0, l = ind.length; i < l; i ++) {
var line = ind[i]
- , lt = line.trim()
+ if (line === undefined) continue
+ var lt = line.trim()
+
if (!ys) {
ys = line.match(/^(\s*)---(.*)$/)
if (ys) {
View
27 test/undefined_indented.js
@@ -0,0 +1,27 @@
+var tap = require("../")
+
+tap.test("consume yaml", function (t) {
+ t.plan(1)
+
+ var s =
+ [ "not ok 1 beep boop"
+ , " ---"
+ , " stack:"
+ , " - rawr"
+ , " - dinosaurs"
+ , " ..."
+ ].join("\n")
+ , c = tap.createConsumer()
+
+ c.on("data", function (res) {
+ t.same(res, {
+ id: 1
+ , ok: false
+ , name: " beep boop" // <-- should perhaps .trim() this?
+ , stack: [ "rawr", "dinosaurs" ]
+ })
+ t.end()
+ })
+ c.write(s)
+ c.end()
+})
Something went wrong with that request. Please try again.