Skip to content

Commit

Permalink
Pax: don't break on line-break-having values or empty keys
Browse files Browse the repository at this point in the history
  • Loading branch information
isaacs committed May 8, 2017
1 parent 09215cd commit 4bfd57b
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 2 deletions.
11 changes: 9 additions & 2 deletions lib/pax.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
'use strict'
const Header = require('./header.js')
const path = require('path')
const assert = require('assert')

class Pax {
constructor (obj, global) {
Expand Down Expand Up @@ -123,10 +122,18 @@ const parseKV = string =>

const parseKVLine = (set, line) => {
const n = parseInt(line, 10)
assert.equal(n, Buffer.byteLength(line) + 1) // + trailing \n

// XXX Values with \n in them will fail this.
// Refactor to not be a naive line-by-line parse.
if (n !== Buffer.byteLength(line) + 1)
return set

line = line.substr((n + ' ').length)
const kv = line.split('=')
const k = kv.shift().replace(/^SCHILY\.(dev|ino|nlink)/, '$1')
if (!k)
return set

const v = kv.join('=')
set[k] = /^([A-Z]+\.)?([mac]|birth|creation)time$/.test(k)
? new Date(v * 1000)
Expand Down
30 changes: 30 additions & 0 deletions test/pax.js
Original file line number Diff line number Diff line change
Expand Up @@ -221,5 +221,35 @@ t.test('parse', t => {
global: false
})

const breaky =
'93 NODETAR.package.readme=karma-moment\n' +
'=================\n' +
'\n' +
'Karma plugin for Moment framework\n' +
'\n'

const noKey = '10 =pathx\n'

t.same(Pax.parse(breaky + '9 gid=20\n10 path=x\n'+noKey, null, false), {
atime: null,
charset: null,
comment: null,
ctime: null,
gid: 20,
gname: null,
linkpath: null,
mtime: null,
path: 'x',
size: null,
uid: null,
uname: null,
dev: null,
ino: null,
nlink: null,
global: false
})



t.end()
})

0 comments on commit 4bfd57b

Please sign in to comment.