Skip to content

Commit

Permalink
Merge 6da3806 into 5897e85
Browse files Browse the repository at this point in the history
  • Loading branch information
media-square committed Feb 13, 2018
2 parents 5897e85 + 6da3806 commit b85c3bb
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions lib/index.js
Expand Up @@ -128,7 +128,7 @@ module.exports = function(opts) {
}

function includeHandler(inst) {
var args = /[^)"']*["']([^"']*)["'](,\s*({[\s\S]*})){0,1}\s*/.exec(inst.args)
var args = /^['|"]([^'|"]*)['|"](,\s*({[\s\S]*}|['|"]([^'|"]*)['|"]|\s*)|)/.exec(inst.args)

This comment has been minimized.

Copy link
@dpilafian

dpilafian Feb 22, 2018

Collaborator

The | in ['|"] at first glance is easy to see as an OR rather than a literal vertical bar character. It might be more clear to use ['"|].

Others have been tripped up by this:
https://stackoverflow.com/a/17221380


if (args) {
var includePath = path.resolve(filebase, args[1])
Expand Down Expand Up @@ -158,7 +158,19 @@ module.exports = function(opts) {
contents: Buffer.from(includeContent)
})

recFile = include(recFile, includeContent, args[3] ? JSON.parse(args[3]) : {})
var data = {};
if(args[4]){
var jsonfile = file.base + args[4];
if (fs.existsSync(jsonfile)) {
data = require(jsonfile)
} else {
return console.error('JSON file not exists:', jsonfile)
}
}else if(args[3]) {
data = JSON.parse(args[3]);
}

recFile = include(recFile, includeContent, data)

return String(recFile.contents)
}
Expand Down

0 comments on commit b85c3bb

Please sign in to comment.