beakerbrowser / webdb

The Web is your database.
https://www.npmjs.com/package/@beaker/webdb
MIT License
399 stars 45 forks source link

Trailing "/" inconsistency for dat URLs #24

Open jakofranko opened 6 years ago

jakofranko commented 6 years ago

When indexing DBs, if you do:

async () => {
    await webdb.indexArchive('dat://232ac2ce8ad4ed80bd1b6de4cbea7d7b0cad1441fa62312c57a6088394717e41/');
console.log(await webdb.listSources());
}

You will see ["dat://232ac2ce8ad4ed80bd1b6de4cbea7d7b0cad1441fa62312c57a6088394717e41"] in your console (note, no trailing /).

If you do this:

...
console.log(webdb.isSource('dat://232ac2ce8ad4ed80bd1b6de4cbea7d7b0cad1441fa62312c57a6088394717e41/');
...

You will see false, because the / at the end is missing. It seems like isSource does an exact string match, when the thing that's important is the dat hash.

A little thing, but it was throwing me off for a bit :)

Any thoughts? It's simple enough, I might make another PR for this unless you have any objections...

pfrazee commented 6 years ago

Yeah that's not right. We should "normalize" the URLs as they get stored/passed into WebDB so that the trailing slash is consistent.