[WIP] A (somewhat barebones) atproto app for creating custom sites without hosting!

server: improve rkey regex

use a more robust regex which ensures colons cannot be used in a record key unless they are valid colon escape syntax

vielle.dev 51173549 dfc59df2

verified
Changed files
+12 -7
server
src
+1 -4
server/src/backfill/new-records.ts
··· 69 69 continue; 70 70 } 71 71 const path = rkeyToUrl(rkey); 72 - if (!path) { 73 - console.warn("rkey not valid!"); 74 - continue; 75 - } 72 + if (!path) continue; 76 73 if (collection !== "dev.atcities.route") continue; 77 74 78 75 switch (op.action) {
+11 -3
server/src/utils.ts
··· 107 107 */ 108 108 export function urlToRkey(url: string): string | undefined { 109 109 // contains 0-9A-Za-z + special valid chars and / seperator. also can contain %XX with XX being hex 110 - if (!url.match(/^([a-zA-Z0-9/\-._~!$&'()*+,;=:@]|(%[0-9a-fA-F]{2}))*$/gm)) { 110 + if ( 111 + !url.match(/^(?:[a-zA-Z0-9/\-._~!$&'()*+,;=:@]|(?:%[0-9a-fA-F]{2}))*$/gm) 112 + ) { 111 113 return; 112 114 } 113 115 return ( ··· 136 138 * @returns {string | undefined} undefined when input is invalid 137 139 */ 138 140 export function rkeyToUrl(rkey: string): string | undefined { 139 - // contains 0-9A-Za-z .-_:~ 140 - if (!rkey.match(/^[A-Za-z0-9.\-_:~]*$/gm)) return; 141 + // contains 0-9A-Za-z .-_~ 142 + // or any valid colon escape sequence 143 + if ( 144 + !rkey.match( 145 + /^(?:[A-Za-z0-9.\-_~]|(?:::)|(?::~)|(?::21)|(?::24)|(?::26)|(?::27)|(?::28)|(?::29)|(?::2A)|(?::2B)|(?::2C)|(?::3A)|(?::3B)|(?::3D)|(?::40))*$/gm 146 + ) 147 + ) 148 + return; 141 149 return rkey 142 150 .replaceAll("::", "/") 143 151 .replaceAll(":~", "%")