MCPcopy Create free account
hub / github.com/GoogleChrome/samples / validateStorageName

Function validateStorageName

sqlite-wasm-cos/sqlite3-node.mjs:16370–16397  ·  view source on GitHub ↗
(n,mayBeJournal=false)

Source from the content-addressed store, hash-verified

16368 it makes names with a "-journal" suffix legal.
16369 */
16370 const validateStorageName = function(n,mayBeJournal=false){
16371 if( kvvfsIsPersistentName(n) ) return;
16372 const len = (new Blob([n])).size/*byte length*/;
16373 if( !len ) toss3(capi.SQLITE_MISUSE, "Empty name is not permitted.");
16374 let maxLen = cache.keySize - 1;
16375 if( cache.rxJournalSuffix.test(n) ){
16376 if( !mayBeJournal ){
16377 toss3(capi.SQLITE_MISUSE,
16378 "Storage names may not have a '-journal' suffix.");
16379 }
16380 }else if( ['-wal','-shm'].filter(v=>n.endsWith(v)).length ){
16381 toss3(capi.SQLITE_MISUSE,
16382 "Storage names may not have a -wal or -shm suffix.");
16383 }else{
16384 maxLen -= 8 /* so we have space for a matching "-journal" suffix */;
16385 }
16386 if( len > maxLen ){
16387 toss3(capi.SQLITE_RANGE, "Storage name is too long. Limit =", maxLen);
16388 }
16389 let i;
16390 for( i = 0; i < len; ++i ){
16391 const ch = n.codePointAt(i);
16392 if( ch<32 ){
16393 toss3(capi.SQLITE_RANGE,
16394 "Illegal character ("+ch+"d) in storage name:",n);
16395 }
16396 }
16397 };
16398
16399 /**
16400 Create a new instance of the objects which go into

Callers 3

sqlite3InitModuleFunction · 0.70
sqlite3_js_kvvfs_importFunction · 0.70
sqlite3_js_kvvfs_reserveFunction · 0.70

Calls 2

kvvfsIsPersistentNameFunction · 0.70
toss3Function · 0.70

Tested by

no test coverage detected