Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
/*
* tst.lib.js: test low-level library functions
*/
var mod_assert = require('assert');
var mod_jsprim = require('jsprim');
var mod_kang = require('../lib/kang');
var mod_nutil = require('../lib/nodeutil');
mod_assert.ok(mod_jsprim.startsWith('grampa/simpson', 'grampa'));
mod_assert.ok(mod_jsprim.startsWith('grampa/simpson', 'grampa/'));
mod_assert.ok(mod_jsprim.startsWith('grampa', 'grampa'));
mod_assert.ok(!mod_jsprim.startsWith('grampa', 'grampa/simpson'));
mod_assert.ok(!mod_jsprim.startsWith('abe', 'grampa/simpson'));
mod_assert.ok(!mod_jsprim.startsWith('grampa/simpson', 'abe'));
mod_assert.equal(mod_nutil.chopSlashes('edna'), 'edna');
mod_assert.equal(mod_nutil.chopSlashes('edna/'), 'edna');
mod_assert.equal(mod_nutil.chopSlashes('edna//'), 'edna');
mod_assert.equal(mod_nutil.chopSlashes('/edna//'), '/edna');
mod_assert.equal(mod_nutil.chopSlashes('/edna/krab/'), '/edna/krab');
mod_assert.equal(mod_nutil.chopSlashes('/edna/krab//'), '/edna/krab');
mod_assert.equal(mod_nutil.chopSlashes('/edna/krab///'), '/edna/krab');
/*
* tst.lib.js: test low-level library functions
*/
var mod_assert = require('assert');
var mod_jsprim = require('jsprim');
var mod_kang = require('../lib/kang');
var mod_nutil = require('../lib/nodeutil');
mod_assert.ok(mod_jsprim.startsWith('grampa/simpson', 'grampa'));
mod_assert.ok(mod_jsprim.startsWith('grampa/simpson', 'grampa/'));
mod_assert.ok(mod_jsprim.startsWith('grampa', 'grampa'));
mod_assert.ok(!mod_jsprim.startsWith('grampa', 'grampa/simpson'));
mod_assert.ok(!mod_jsprim.startsWith('abe', 'grampa/simpson'));
mod_assert.ok(!mod_jsprim.startsWith('grampa/simpson', 'abe'));
mod_assert.equal(mod_nutil.chopSlashes('edna'), 'edna');
mod_assert.equal(mod_nutil.chopSlashes('edna/'), 'edna');
mod_assert.equal(mod_nutil.chopSlashes('edna//'), 'edna');
mod_assert.equal(mod_nutil.chopSlashes('/edna//'), '/edna');
mod_assert.equal(mod_nutil.chopSlashes('/edna/krab/'), '/edna/krab');
mod_assert.equal(mod_nutil.chopSlashes('/edna/krab//'), '/edna/krab');
mod_assert.equal(mod_nutil.chopSlashes('/edna/krab///'), '/edna/krab');
/*
* tst.lib.js: test low-level library functions
*/
var mod_assert = require('assert');
var mod_jsprim = require('jsprim');
var mod_kang = require('../lib/kang');
var mod_nutil = require('../lib/nodeutil');
mod_assert.ok(mod_jsprim.startsWith('grampa/simpson', 'grampa'));
mod_assert.ok(mod_jsprim.startsWith('grampa/simpson', 'grampa/'));
mod_assert.ok(mod_jsprim.startsWith('grampa', 'grampa'));
mod_assert.ok(!mod_jsprim.startsWith('grampa', 'grampa/simpson'));
mod_assert.ok(!mod_jsprim.startsWith('abe', 'grampa/simpson'));
mod_assert.ok(!mod_jsprim.startsWith('grampa/simpson', 'abe'));
mod_assert.equal(mod_nutil.chopSlashes('edna'), 'edna');
mod_assert.equal(mod_nutil.chopSlashes('edna/'), 'edna');
mod_assert.equal(mod_nutil.chopSlashes('edna//'), 'edna');
mod_assert.equal(mod_nutil.chopSlashes('/edna//'), '/edna');
mod_assert.equal(mod_nutil.chopSlashes('/edna/krab/'), '/edna/krab');
mod_assert.equal(mod_nutil.chopSlashes('/edna/krab//'), '/edna/krab');
mod_assert.equal(mod_nutil.chopSlashes('/edna/krab///'), '/edna/krab');
inputstream.on('data', function (input) {
var path, relpath, localpath, tmppath;
path = input.path;
log.debug('check index "%s"', path);
if (!mod_jsprim.startsWith(path, indexroot)) {
console.error(
'warn: input "%s" not under index root', path);
return;
}
relpath = path.substr(indexroot.length);
localpath = mod_path.join(cacheroot, relpath);
tmppath = localpath + '.tmp';
barrier.start(relpath);
mod_fs.stat(localpath, function (err, st) {
if (!err) {
log.debug('have index "%s"', path);
barrier.done(relpath);
return;
}
function knMakeSource(str)
{
var protocol, host, portstr, port, uri, c, matched;
if (mod_jsprim.startsWith(str, 'https://')) {
protocol = 'https';
port = 443;
str = str.substr('https://'.length);
} else {
protocol = 'http';
port = 80;
if (mod_jsprim.startsWith(str, 'http://'))
str = str.substr('http://'.length);
}
c = str.indexOf('/');
if (c == -1) {
uri = knDefaultUri;
} else {
uri = str.substr(c);
if (b['aggr'] == 'lquantize') {
if (!b.hasOwnProperty('step'))
return (new VError('aggr "lquantize" ' +
'requires "step"'));
step = parseInt(b['step'], 10);
if (isNaN(step))
return (new VError('aggr "lquzntize":' +
' invalid value for "step": "%s"',
b['step']));
b['step'] = step;
}
}
if ((!options || !options.allowReserved) &&
mod_jsprim.startsWith(b.name, '__dn'))
return (new VError('field names starting with ' +
'"__dn" are reserved'));
if (!b.hasOwnProperty('field'))
b['field'] = b['name'];
return (b);
}
function knMakeSource(str)
{
var protocol, host, portstr, port, uri, c, matched;
if (mod_jsprim.startsWith(str, 'https://')) {
protocol = 'https';
port = 443;
str = str.substr('https://'.length);
} else {
protocol = 'http';
port = 80;
if (mod_jsprim.startsWith(str, 'http://'))
str = str.substr('http://'.length);
}
c = str.indexOf('/');
if (c == -1) {
uri = knDefaultUri;
} else {
uri = str.substr(c);
str = str.substr(0, c);
}
if ((matched = IPV4_HOST.exec(str)) !== null) {
host = matched[1];
portstr = matched[2];
if (!mod_net.isIPv4(host)) {
throw new Error('bad IPv4 address: ' +
return (function filterPathByTime(path) {
var tail;
mod_assertplus.ok(mod_jsprim.startsWith(path, root));
tail = path.substr(root.length);
return (filter.rangeContains(start, end, tail));
});
};