Example #1
0
var sanitizeHomepage = function(input) {
  // URL
  if (isURL(input)) return input

  // Not-fully-qualified URL
  if (isURL("http://"+input)) return "http://"+input
}
Example #2
0
const resolve = (originPath, filePath, fileName) => {
  if (isUrl(fileName)) {
    return fileName
  }

  if (isUrl(originPath)) {
    return resolveURL(filePath, fileName)
  }

  return resolveFS(originPath, filePath, fileName)
}
Example #3
0
Dcat.prototype.url = function(pathnameOrCurie){
  if (isUrl(pathnameOrCurie)) {
    return pathnameOrCurie;
  }

  var protocol, hostname, port, pathname;
  var splt = pathnameOrCurie.split(':');

  if (splt.length === 2) { // CURIE
    var ctx = SchemaOrgIo.context()['@context'][1];
    if (splt[0] in ctx) {
      if (splt[0] === 'ldr') {
        protocol = this.rc.protocol;
        hostname = this.rc.hostname;
        port = this.rc.port;
      } else {
        var purl = url.parse(ctx[splt[0]]);
        protocol = purl.protocol;
        hostname = purl.hostname;
        port = purl.port;
      }
      pathname = splt[1];
    } else {
      throw new Error('unsupported CURIE prefix: ' + splt[0]);
    }
  } else { //<-pathname
    protocol = this.rc.protocol;
    hostname = this.rc.hostname;
    port = this.rc.port;
    pathname = pathnameOrCurie;
  }

  return protocol + '//'  + hostname + ((port && (port !== 80 && port !== 443)) ? (':' + port) : '') + '/' + pathname.replace(/^\/|\/$/g, '');
};
    _.each(articles, (item) => {

      expect(item).to.include.keys('url', 'title', 'published')
      expect(isISOString(item.published)).to.equal(true, '必須要有 published')
      expect(isUrl(item.url)).to.equal(true, '必須要有 url')
      expect(item.title).to.be.a('string', '必須要有 title')
    })
  got.get(requestUrl).then((response) => {
    let json;

    try {
      json = JSON.parse(response.body);
    } catch (err) {
      return cb(parseFailedResponse());
    }

    const bestMatchUrl = xpathHelper(json, config.xpaths);
    let url = repositoryUrl(bestMatchUrl);

    if (!url && isUrl(bestMatchUrl)) {
      url = bestMatchUrl;
    }

    if (!url && config.fallback) {
      url = util.format(config.fallback, packageName);
    }

    if (!url) {
      return cb(repositoryUrlNotFoundResponse());
    }

    got.get(url).then(() => {
      cb(null, url);
    }).catch(() => {
      url = util.format(config.fallback, packageName);
      cb(null, url);
    });
  }, (err) => {
export default (elm) => {
  if (!elm || (elm.tagName && elm.tagName.toLowerCase() === 'article')) {
    return null;
  }

  const content = elm.textContent || '';
  if (!content.match(/^https?:\/\//) || !isUrl(content)) {
    return null;
  }

  if (isImage(content)) {
    return {
      type: 'embed',
      embedType: 'image',
      src: content
    };
  }

  const parsed = parseEmbeds(content);
  if (!parsed || !isValidEmbedType(parsed)) {
    return null;
  }

  return objectAssign({}, parsed, {
    embedType: parsed.type,
    type: 'embed'
  });
};
/*
 * Takes the specified target and returns the moduleID
 * If the git repoName is different than moduleID, then the 
 * output from this function will be incorrect. This is the 
 * backup way to get ID. getJsonDiff is the preferred way to 
 * get the moduleID of the installed module.
 *
 * @param {String} target    target that was passed into cordova-fetch.
 *                           can be moduleID, moduleID@version or gitURL
 *
 * @return {String} ID       moduleID without version.
 */
function trimID(target) {
    var parts;

    //If GITURL, set target to repo name
    if (isUrl(target)) {
        //strip away .git and everything that follows       
        var strippedTarget = target.split('.git');
        var re = /.*\/(.*)/;
        //Grabs everything in url after last `/`
        parts = strippedTarget[0].match(re);
        
        target = parts[1];
    }
    
    //strip away everything after '@'
    //also support scoped packages
    if(target.indexOf('@') != -1) {
        parts = target.split('@');
        if (parts.length > 1 && parts[0] === '') {
            //scoped package
            target = '@' + parts[1];
        } else {
            target = parts[0];
        }
    }        
    
    return target;
}
Example #8
0
  onDropOrPaste = (event, change, editor) => {
    const target = getEventRange(event, change.value)
    if (!target && event.type == 'drop') return

    const transfer = getEventTransfer(event)
    const { type, text, files } = transfer

    if (type == 'files') {
      for (const file of files) {
        const reader = new FileReader()
        const [mime] = file.type.split('/')
        if (mime != 'image') continue

        reader.addEventListener('load', () => {
          editor.change(c => {
            c.call(insertImage, reader.result, target)
          })
        })

        reader.readAsDataURL(file)
      }
    }

    if (type == 'text') {
      if (!isUrl(text)) return
      if (!isImage(text)) return
      change.call(insertImage, text, target)
    }
  }
  function resolveScriptTagSrc(scriptTag, document) {
    const path = scriptTag.src.split('/');
    const filename = path[path.length - 1];
    const src = scriptTag.src;

    if (!isUrl(src)) {
      numScriptsResolved += 1;
      return;
    }

    request({ method: 'GET', url: src, encoding: null }, (err, response, body) => {
      if (err) {
        console.log(err);
      } else {
        zip.append(body, { name: filename });
        scriptTag.src = filename;
      }

      numScriptsResolved += 1;
      if (numScriptsResolved === numScriptTags) {
        indexHtml.content = serializeDocument(document);
        callback();
      }
    });
  }
Example #10
0
const downloadFileTempAsync = (filePath, tmpDir) => {
  const iconFileName = `webcatalog-${Date.now()}.png`;
  const iconPath = path.join(tmpDir, iconFileName);

  if (isUrl(filePath)) {
    return new Promise((resolve, reject) => {
      const iconFile = fs.createWriteStream(iconPath);

      const req = https.get(filePath, (response) => {
        response.pipe(iconFile);

        iconFile.on('error', (err) => {
          reject(err);
        });

        iconFile.on('finish', () => {
          resolve(iconPath);
        });
      });

      req.on('error', (err) => {
        reject(err);
      });
    });
  }

  return fs.copy(filePath, iconPath)
    .then(() => iconPath);
};
Example #11
0
    _.each(jsonObject, function(value, key){
        if(value.type == "directory"){
            /* 目录 */
            dirPath = path.join(baseDir, key);
            filesystem.makedirsSync(dirPath);

            // 是否有children字段(代表有子目录/文件)
            if(value.children){
                jsonToDir(value.children, dirPath);
            }
        }else{
            /* 文件 */
            fileDirName = path.join(baseDir, key);

            if(value.content){
                if(isurl(value.content)){
                    // 远程文件
                    requestUrlContent(value.content).then(function(){
                        fileContent = arguments[0];

                        fs.writeFileSync(fileDirName, fileContent);
                    });
                }else{
                    fileContent = value.content;

                    fs.writeFileSync(fileDirName, fileContent);
                }
            }else{
                fs.writeFileSync(fileDirName, "");
            }
        }
    });
Example #12
0
var notFound = function (file, options) {
  options = options || {};
  
  if (options.exists) fileExists = options.exists;
  
  if (!isUrl(file) && !fileExists(file) && !fs.existsSync(file)) {
    file = options._default;
  }
  
  return function (req, res, next) {
    var reqOptions = {
      statusCode: 404,
      headers: options.headers
    };
    
    if (!file) return next();
    
    req.url = file;
    
    if (options.fullPath) {
      var p = options.fullPath(file);
      reqOptions.root = p.root;
      req.url = p.pathname;
    }
    
    res.statusCode = 404;
    deliver(req, res, reqOptions).pipe(res);
  };
};
Example #13
0
ref.on("child_added", function(snapshot) {
    var url = snapshot.val().url;
    var filename = snapshot.val().fileName;
    if (isUrl(url) && !fileExists('./downloadedFiles/' + filename)) {
        downloadFile(url, filename);
        resetDb(ref);
    }
}, function (errorObject) {
Example #14
0
 it('redos exploit', function () {
   // Invalid. This should be discovered in under 1 second.
   var attackString = 'a://localhost' + '9'.repeat(100000) + '\t';
   var before = process.hrtime();
   assert(!url(attackString), 'attackString was valid');
   var elapsed = process.hrtime(before);
   assert(elapsed[0] < 1, 'attackString took ' + elapsed[0] + ' > 1 seconds');
 });
Example #15
0
 .then(function () {
   console.info(figures.tick + ' found addon "' + argv.addon + '"')
   if (isUrl(argv.addon)) {
     return getMeta(argv.addon, argv)
   } else {
     return npmInstall(addon, argv)
   }
 })
Example #16
0
 function pathExists (config, settings) {
   if (!config || !config.error_page) return false;
   if (isUrl(config.error_page)) return true;
   
   // NOTE: If this becomes a bottleneck, convert 
   // to async version of fs.exists()
   return settings.isFile(join(config.root, config.error_page));
 }
Example #17
0
function Pkg(pkg, root, opts){
  opts = opts || {};
  
  this.pkg = pkg;
  this.root = (root) ? path.resolve(root): process.cwd();

  //if !base in this -> will throw if based is needed. if this.based === undefined try to get a base by dereferencing context url
  if(pkg['@context']){
    if(isUrl(pkg['@context'])){
      this.base = undefined; //will be resolved at first request if needed...
    } else if ( (typeof pkg['@context'] === 'object') && ('@base' in pkg['@context']) && isUrl(pkg['@context']['@base']) ) {
      this.base = pkg['@context']['@base'];
    }
  } else if(opts.base && isUrl(opts.base)) {
    this.base = opts.base;
  }

};
AssertionVisitor.prototype.enter = function (currentNode, parentNode) {
    this.canonicalCode = this.generateCanonicalCode(currentNode);
    this.powerAssertCalleeObject = this.guessPowerAssertCalleeObjectFor(currentNode.callee);

    if (this.sourceMapConsumer) {
        var pos = this.sourceMapConsumer.originalPositionFor({
            line: currentNode.loc.start.line,
            column: currentNode.loc.start.column
        });
        if (pos) {
            // console.log(JSON.stringify(pos, null, 2));
            if (pos.source) {
                if (this.sourceMapConsumer.sourceRoot && isUrl(this.sourceMapConsumer.sourceRoot)) {
                    this.filepath = _path.relative(this.sourceMapConsumer.sourceRoot, pos.source);
                } else if (this.options.sourceRoot && isAbsolute(this.options.sourceRoot) && isAbsolute(pos.source)) {
                    this.filepath = _path.relative(this.options.sourceRoot, pos.source);
                } else if (this.sourceMapConsumer.sourceRoot && isAbsolute(this.sourceMapConsumer.sourceRoot) && isAbsolute(pos.source)) {
                    this.filepath = _path.relative(this.sourceMapConsumer.sourceRoot, pos.source);
                } else if (isUrl(pos.source)) {
                    this.filepath = _path.basename(pos.source);
                } else {
                    this.filepath = pos.source;
                }
            }
            if (pos.line) {
                this.lineNum = pos.line;
            }
        }
    }

    if (!this.filepath) {
        if (this.options.sourceRoot && isAbsolute(this.options.sourceRoot) && isAbsolute(this.options.path)) {
            this.filepath = _path.relative(this.options.sourceRoot, this.options.path);
        } else {
            this.filepath = this.options.path;
        }
    }

    this.filepath = fallbackOnBasename(this.filepath);

    if (!this.lineNum) {
        this.lineNum = currentNode.loc.start.line;
    }
};
Example #19
0
 function pathWithRoot (config, settings) {
   if (isUrl(config.error_page)) return config.error_page;
   return store.getPath(join(
     '/',
     req.config.cwd || '/',
     req.config.root || 
     '/',
     config.error_page
   ));
 }
Example #20
0
  return ($) => {
    let value = rule($)
    if (typeof value != 'string') return

    // make sure it's a url
    value = value.trim()
    if (!isUrl(value)) return

    return value
  }
Example #21
0
    copyFile: function (source, target, callback) {

        // Executer callback avec readstream en parametre sauf si erreur de lecture
        function localReadStream (source, pipeStreams) {
            // Test if file exists and is readable
            fs.access(source, fs.F_OK | fs.R_OK, function (err) {
                if (!err) {
                    var readStream = fs.createReadStream(source);
                    readStream.on("error", function (err) {
                        pipeStreams(err);
                    });
                    pipeStreams(readStream);
                } else {
                    pipeStreams(err);
                }
            });
        }

        // Idem en ligne
        function remoteReadStream (source, pipeStreams) {
            request(source, function(err, response)  {
                if (err) {
                    pipeStreams(err);
                } else if (response.statusCode === 200) {
                    var stream = request.get(source)
                                        .on("error", function(err){
                                            console.error(err);
                                        });
                    pipeStreams(stream);
                } else {
                    pipeStreams(false);
                }
            });
        }

        function pipeStreams (readStream) {
            if (readStream && !readStream.pipe || typeof readStream.pipe !== "function") {
                callback(readStream);
                return;
            }
            var writeStream = fs.createWriteStream(target);
            readStream.pipe(writeStream);
            writeStream.on("finish", function() {
                writeStream.close(callback);
            });
        }

        callback = typeof callback === "function" ? callback : function () { return; };
        this.createDir(target);
        if (!isUrl(source)) {
            localReadStream(source, pipeStreams);
        } else {
            remoteReadStream(source, pipeStreams);
        }
    },
Example #22
0
module.exports = function(repo_url) {
  var obj = {}

  if (!repo_url) return null

  var shorthand = repo_url.match(/^([\w-_]+)\/([\w-_\.]+)#?([\w-_\.]+)?$/)
  var mediumhand = repo_url.match(/^github:([\w-_]+)\/([\w-_\.]+)#?([\w-_\.]+)?$/)
  var antiquated = repo_url.match(/^git@[\w-_\.]+:([\w-_]+)\/([\w-_\.]+)$/)

  if (shorthand) {
    obj.user = shorthand[1]
    obj.repo = shorthand[2]
    obj.branch = shorthand[3] || "master"
  } else if (mediumhand) {
    obj.user = mediumhand[1]
    obj.repo = mediumhand[2]
    obj.branch = mediumhand[3] || "master"
  } else if (antiquated) {
    obj.user = antiquated[1]
    obj.repo = antiquated[2].replace(/\.git$/i, "")
    obj.branch = "master"
  } else {
    if (!isUrl(repo_url)) return null
    var parsedURL = url.parse(repo_url)
    if (parsedURL.hostname != "github.com") return null
    var parts = parsedURL.pathname.match(/^\/([\w-_]+)\/([\w-_\.]+)(\/tree\/[\w-_\.]+)?(\/blob\/[\w-_\.]+)?/)
    // ([\w-_\.]+)
    if (!parts) return null
    obj.user = parts[1]
    obj.repo = parts[2].replace(/\.git$/i, "")

    if (parts[3]) {
      obj.branch = parts[3].replace(/^\/tree\//, "")
    } else if (parts[4]) {
      obj.branch = parts[4].replace(/^\/blob\//, "")
    } else {
      obj.branch = "master"
    }

  }

  obj.tarball_url = util.format("https://api.github.com/repos/%s/%s/tarball/%s", obj.user, obj.repo, obj.branch)

  if (obj.branch === "master") {
    obj.https_url = util.format("https://github.com/%s/%s", obj.user, obj.repo)
    obj.travis_url = util.format("https://travis-ci.org/%s/%s", obj.user, obj.repo)
  } else {
    obj.https_url = util.format("https://github.com/%s/%s/tree/%s", obj.user, obj.repo, obj.branch)
    obj.travis_url = util.format("https://travis-ci.org/%s/%s?branch=%s", obj.user, obj.repo, obj.branch)
  }

  obj.api_url = util.format("https://api.github.com/repos/%s/%s", obj.user, obj.repo)

  return obj
}
Example #23
0
function getSha1(uri){
  if(!isUrl(uri)){
    return uri.replace(/^\/|\/$/g, '').split('/')[1];
  } else {
    purl = url.parse(uri);
    if(purl.hostname === 'registry.standardanalytics.io'){
      return purl.pathname.replace(/^\/|\/$/g, '').split('/')[1];
    }
  }
  return undefined;
};
Example #24
0
 function getImageUrl (href) {
     if (isUrl(href)) {
         return href;
     }
     var parsedPath = parsePath(href);
     if (parsedPath.isAbsolute) {
         return parsedPath.absolute;
     } else {
         return pathModule.join(process.cwd(), href);
     }
 }
Example #25
0
      function next(err, obj, $) {
        if (err) return fn(err);
        var paginate = state.paginate;
        var paging = state.paging;
        var limit = --state.limit;

        // create the stream
        stream = stream
          ? stream
          : paginate
          ? stream_array(state.stream)
          : stream_object(state.stream);

        if (paginate) {
          if (typeof paging === 'function') {
            paging(obj);
          } else if (isArray(obj)) {
            pages = pages.concat(obj);
          } else {
            pages.push(obj);
          }

          if (limit <= 0) {
            debug('reached limit, ending');
            stream(obj, true);
            return fn(null, pages);
          }

          var url = resolve($, false, paginate);
          debug('paginate(%j) => %j', paginate, url);

          if (!isUrl(url)) {
            debug('%j is not a url, finishing up', url);
            stream(obj, true);
            return fn(null, pages);
          }

          stream(obj);

          // debug
          debug('paginating %j', url);
          isFinite(limit) && debug('%s page(s) left to crawl', limit)

          xray.request(url, function(err, html) {
            if (err) return next(err);
            var $ = load(html, url);
            node.html($, next);
          });

        } else {
          stream(obj, true);
          fn(null, obj);
        }
      }
Example #26
0
roo.get(/\/(.+)/, function *(next) {
  var url = this.params[0];
  if (!url || !is_url(url)) {
    return yield next;
  }

  // run the page pipe
  // TODO: yieldable
  this.body = yield function(done) {
    pagepipe(url, done);
  }
})
Example #27
0
  renderContent(): any {
    const value = this.props.cell.get('value');

    if (isImage(value)) {
      return <Image src={value} responsive />;
    }
    if (isUrl(value)) {
      return <a href={value}>{value}</a>;
    }

    return value;
  }
function fallbackOnBasename (filepath) {
    if (filepath) {
        if (filepath.split(_path.sep).indexOf('..') !== -1) {
            return _path.basename(filepath);
        } else if (isUrl(filepath)) {
            return _path.basename(filepath);
        } else if (isAbsolute(filepath)) {
            return _path.basename(filepath);
        }
    }
    return filepath;
}
Example #29
0
var sanitizeTwitterHandle = function(input) {
  // URL
  if (isURL(input)) return URL.parse(input).path.replace("/", "")

  // Not-fully-qualified URL
  var twittery = new RegExp("^twitter.com/", "i")
  if (input.match(twittery)) return input.replace(twittery, "")

  // Starts with @
  if (input.match(atty)) return input.replace(atty, "")

  return input
}
Example #30
0
var sanitizeGitHubHandle = function(input) {
  // URL
  if (isURL(input)) return URL.parse(input).path.replace("/", "")

  // Not-fully-qualified URL
  var githubby = new RegExp("^github.com/", "i")
  if (input.match(githubby)) return input.replace(githubby, "")

  // Starts with @
  if (input.match(atty)) return input.replace(atty, "")

  return input
}