Skip to content

Commit

Permalink
load js-yaml full schema support to allow regexp
Browse files Browse the repository at this point in the history
  • Loading branch information
itkoren committed Nov 30, 2014
1 parent 4f02cb4 commit 0b437e5
Show file tree
Hide file tree
Showing 6 changed files with 12 additions and 5 deletions.
2 changes: 1 addition & 1 deletion lib/readfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ module.exports = function(file) {
// YAML file
if (ext.match(/ya?ml/)) {
var res = fs.readFileSync(file, 'utf8');
return yaml.safeLoad(res);
return yaml.safeLoad(res, { schema: yaml.DEFAULT_FULL_SCHEMA });
}

// JS / JSON / CoffeeScript
Expand Down
3 changes: 2 additions & 1 deletion test/config/jsonfile.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
{
"jsonFile": {
"options": {
"filename": "read.json"
"filename": "read.json",
"regexp": "/(\\d{1,})\\%/"
}
}
}
1 change: 1 addition & 0 deletions test/config/yamlfile.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
yamlFile:
options:
filename: read.yaml
regexp: !!js/regexp /(\d{1,})\%/
1 change: 1 addition & 0 deletions test/config/ymlfile.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
ymlFile:
options:
filename: read.yml
regexp: !!js/regexp /(\d{1,})\%/
9 changes: 6 additions & 3 deletions test/fixtures/output.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,21 +37,24 @@ module.exports = {
jsonfile: {
jsonFile: {
options: {
filename: 'read.json'
filename: 'read.json',
regexp: '/(\\d{1,})\\%//'
}
}
},
yamlfile: {
yamlFile: {
options: {
filename: 'read.yaml'
filename: 'read.yaml',
regexp: '/(\\d{1,})\\%//'
}
}
},
ymlfile: {
ymlFile: {
options: {
filename: 'read.yml'
filename: 'read.yml',
regexp: '/(\\d{1,})\\%//'
}
}
}
Expand Down
1 change: 1 addition & 0 deletions test/readfile.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ suite('readfile', function() {
test('read yml file', function() {
var yaml = readfile(__dirname+'/config/ymlfile.yml');
assert.equal(yaml.ymlFile.options.filename, 'read.yml');
assert.equal(yaml.ymlFile.options.regexp, '/(\\d{1,})\\%/');
});

test('read json file', function() {
Expand Down

0 comments on commit 0b437e5

Please sign in to comment.