dat-encoding
Advanced tools
Comparing version 5.0.0 to 5.0.1
@@ -15,3 +15,5 @@ 'use strict' | ||
if (typeof str !== 'string') throw new Error('Not a string') | ||
var match = /\/?([^/]{64,65})/.exec(str) | ||
// looking for an hexa string of 64 or 65 consecutive chars | ||
var match = /([a-f0-9]{64,65})/i.exec(str) | ||
// we need exactly 64, so an hexa string with 65 chars (or more) is not allowed | ||
if (!match || match[1].length !== 64) throw new Error('Invalid key') | ||
@@ -18,0 +20,0 @@ return Buffer.from(match[1], 'hex') |
{ | ||
"name": "dat-encoding", | ||
"version": "5.0.0", | ||
"version": "5.0.1", | ||
"license": "MIT", | ||
@@ -5,0 +5,0 @@ "repository": "juliangruber/dat-encoding", |
20
test.js
@@ -12,5 +12,5 @@ var test = require('tape') | ||
{type: 'valid', key: 'host.com/whatever/6161616161616161616161616161616161616161616161616161616161616161'}, | ||
{type: 'invalid', key: 'z6161616161616161616161616161616161616161616161616161616161616161'}, | ||
{type: 'valid', key: 'z6161616161616161616161616161616161616161616161616161616161616161'}, | ||
{type: 'valid', key: '6161616161616161616161616161616161616161616161616161616161616161z'}, | ||
{type: 'invalid', key: '6161616161616161616161616161z616161616161616161616161616161616161'}, | ||
{type: 'invalid', key: '6161616161616161616161616161616161616161616161616161616161616161z'}, | ||
{type: 'invalid', key: '616161616161616161616161616161616161616161616161616161616161616'}, | ||
@@ -85,3 +85,3 @@ {type: 'invalid', key: '61616161616161616161616161616161616161616161616161616161616161601'}, | ||
t.equal(typeof newKey, 'string') | ||
t.ok(enc.decode(newKey), 'valid key is now valid buf') | ||
t.ok(enc.decode(newKey), 'valid key is now valid buffer') | ||
} | ||
@@ -108,1 +108,15 @@ }) | ||
}) | ||
test('toStr with path', function (t) { | ||
t.plan(2) | ||
var newKey = enc.toStr('3161616161616161616161616161616161616161616161616161616161616161/path') | ||
t.equal(newKey, '3161616161616161616161616161616161616161616161616161616161616161') | ||
t.ok(enc.decode(newKey), 'valid key is now valid buffer') | ||
}) | ||
test('toStr with version', function (t) { | ||
t.plan(2) | ||
var newKey = enc.toStr('4161616161616161616161616161616161616161616161616161616161616161+5') | ||
t.equal(newKey, '4161616161616161616161616161616161616161616161616161616161616161') | ||
t.ok(enc.decode(newKey), 'valid key is now valid buffer') | ||
}) |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
6892
127