INNER CODE UNIT · JavaScript

autoEntry

wangshengithub/staticshield · src/server.js:20

function autoEntry(files) {
  var rootHtml = null, any = null;
  for (var i = 0; i < files.length; i++) {
    var p = String(files[i].path || '').replace(/^\.\//, '');
    if (/\.html?$/i.test(p)) { any = any || p; if (p.indexOf('/') === -1) { rootHtml = p; break; } }
  }
  return rootHtml || any;
}
function resolveSafely(tmpDir, fileRel) {
  fileRel = String(fileRel || '').replace(/^\.\//, '').replace(/\\/g, '/');
  if (!fileRel || fileRel.indexOf('..') >= 0 || /^[\\/]/.test(fileRel)) throw new Error('非法文件路径');
  var fp = path.join(tmpDir, fileRel);
  var rel = path.relative(tmpDir, fp);
  if (rel === '' || rel.indexOf('..') === 0 || path.isAbsolute(rel)) throw new Error('文件路径越界');
  return fp;
}
function safeWrite(tmpDir, fileRel, content, isDataUri) {
  var fp = resolveSafely(tmpDir, fileRel);

View source record →

📰 Research Paper
Loading…
⏳ Fetching content…