Skip to content
This repository has been archived by the owner on Jun 28, 2021. It is now read-only.

Commit

Permalink
escape: validation refinements
Browse files Browse the repository at this point in the history
  • Loading branch information
wdavidw committed Dec 29, 2018
1 parent 8f34bb0 commit f3d86b2
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 4 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Expand Up @@ -5,6 +5,7 @@

Enhancements:

* escape: validation refinements
* skip_empty_lines: validation refinements
* skip_lines_with_empty_values: validation refinements
* skip_lines_with_error: validation refinements
Expand Down
5 changes: 3 additions & 2 deletions lib/es5/index.js
Expand Up @@ -50,7 +50,6 @@ var _require = require('stream'),
var ResizeableBuffer = require('./ResizeableBuffer');

var default_options = {
escape: Buffer.from('"'),
from: 1,
from_line: 1,
objname: undefined,
Expand Down Expand Up @@ -164,7 +163,9 @@ function (_Transform) {
} // Normalize option `escape`


if (typeof options.escape === 'string') {
if (options.escape === undefined || options.escape === null) {
options.escape = Buffer.from('"');
} else if (typeof options.escape === 'string') {
options.escape = Buffer.from(options.escape);
}

Expand Down
5 changes: 3 additions & 2 deletions lib/index.js
Expand Up @@ -10,7 +10,6 @@ const { Transform } = require('stream')
const ResizeableBuffer = require('./ResizeableBuffer')

const default_options = {
escape: Buffer.from('"'),
from: 1,
from_line: 1,
objname: undefined,
Expand Down Expand Up @@ -102,7 +101,9 @@ class Parser extends Transform {
throw new Error(`Invalid Option: delimiter must be a string or a buffer, got ${options.delimiter}`)
}
// Normalize option `escape`
if(typeof options.escape === 'string'){
if(options.escape === undefined || options.escape === null){
options.escape = Buffer.from('"')
}else if(typeof options.escape === 'string'){
options.escape = Buffer.from(options.escape)
}
if(!Buffer.isBuffer(options.escape)){
Expand Down
12 changes: 12 additions & 0 deletions test/option.escape.coffee
Expand Up @@ -3,6 +3,18 @@ parse = require '../lib'

describe 'Option `escape`', ->

it 'validation', ->
parse '', escape: '\\', (->)
parse '', escape: Buffer.from('\\'), (->)
parse '', escape: null, (->)
parse '', escape: undefined, (->)
(->
parse '', escape: false, (->)
).should.throw 'Invalid Option: escape must be a buffer or a string, got false'
(->
parse '', escape: true, (->)
).should.throw 'Invalid Option: escape must be a buffer or a string, got true'

describe 'same as quote', ->

it 'is same as quote', (next) ->
Expand Down

0 comments on commit f3d86b2

Please sign in to comment.