include-folder icon indicating copy to clipboard operation
include-folder copied to clipboard

include-folder fails if given a Windows-style path name

Open robsussman opened this issue 7 years ago • 0 comments

Trying to use include-folder on Windows fails with an error like this:

undefined:4 self["foo"] = fs.readFileSync("C:\Users\rob\Documents\xdev\foo.js","utf8"); ^^^^ SyntaxError: Invalid hexadecimal escape sequence at new Function () at includeFolder (C:\Users\rob\Documents\xdev\node_modules\include-folder\lib\include-folder.js:17:11)

I believe the problem is in the includeFolder.buildSource function where it creates a string that is then parsed via the javascript Function object. If this string has characters that should be escaped then the subsequent parsing will fail.

The following change fixed the issue for me:

  • var jsStringEscape = require('js-string-escape');
  • return 'self["' + name + '"] = fs.readFileSync("' + folderName + '/' + fileName + '","utf8");';
  • return 'self["' + name + '"] = fs.readFileSync("' + jsStringEscape(folderName) + '/' + fileName + '","utf8");';

robsussman avatar Apr 11 '18 16:04 robsussman