~ knotless Search/
↑↓ move↵ open⇧↵ all results

zat.dev/zds

atproto pds · mirror of https://tangled.org/zat.dev/zds

0
0
62 lines · 3.3 KB Raw History
diff --git a/dist/aturi_validation.js b/dist/aturi_validation.js
index 86fbacf9e5309cc80be4d576b614f464a7cc8e3c..921fe61b67095a94f0dcfcde076716c350114eed 100644
--- a/dist/aturi_validation.js
+++ b/dist/aturi_validation.js
@@ -82,8 +82,9 @@ export class InvalidAtUriError extends Error {
 }
 const INVALID_CHAR_REGEXP = /[^a-zA-Z0-9._~:@!$&'()*+,;=%/\\[\]#?-]/;
 const AT_URI_REGEXP = /^(?<uri>at:\/\/(?<authority>[^/?#\s]+)(?:\/(?<collection>[^/?#\s]+)(?:\/(?<rkey>[^/?#\s]+))?)?(?<trailingSlash>\/)?)(?:\?(?<query>[^#\s]*))?(?:#(?<hash>[^\s]*))?$/;
-export const SPACE_MARKER = 'space';
-const SPACE_AT_URI_REGEXP = /^at:\/\/(?<authority>[^/?#\s]+)\/space\/(?<spaceType>[^/?#\s]+)\/(?<skey>[^/?#\s]+)(?:\/(?<authorDid>[^/?#\s]+)\/(?<collection>[^/?#\s]+)\/(?<rkey>[^/?#\s]+))?(?<trailingSlash>\/)?(?:\?(?<query>[^#\s]*))?(?:#(?<hash>[^\s]*))?$/;
+export const SPACE_URI_PREFIX = 'at:space/';
+export const SPACE_MARKER = "space";
+const SPACE_AT_URI_REGEXP = /^at:space\/(?<authority>[^/?#\s]+)\/(?<spaceType>[^/?#\s]+)\/(?<skey>[^/?#\s]+)(?:\/(?<authorDid>[^/?#\s]+)\/(?<collection>[^/?#\s]+)\/(?<rkey>[^/?#\s]+))?(?<trailingSlash>\/)?(?:\?(?<query>[^#\s]*))?(?:#(?<hash>[^\s]*))?$/;
 /**
  * Parses a valid {@link AtUriString} into a {@link AtUriParts} object, or
  * returns a failure with a detailed error message if the string is not a valid
@@ -100,8 +101,6 @@ export function parseAtUriString(input, options) {
     if (invalidChar) {
         return failure('Disallowed characters in ATURI (ASCII)');
     }
-    // Space URIs carry extra path segments the public grammar disallows, so they
-    // get their own validation.
     if (isSpaceUri(input)) {
         return parseSpaceAtUriString(input, options);
     }
@@ -113,7 +112,7 @@ export function parseAtUriString(input, options) {
         // a generic error.
         if (options?.detailed) {
             if (!input.startsWith('at://')) {
-                return failure('ATURI must start with "at://"');
+                return failure('ATURI must start with "at://" or "at:space/"');
             }
             if (input.includes(' ')) {
                 return failure('ATURI can not contain spaces');
@@ -168,19 +167,11 @@ export function parseAtUriString(input, options) {
     return success({ ...groups, isSpace: false });
 }
 /**
- * Whether a string addresses permissioned space data. Checks only for the `space`
- * marker — use {@link isAtUriString} to validate the URI itself.
+ * Whether a string addresses permissioned space data. Checks only for the
+ * `at:space/` prefix — use {@link isAtUriString} to validate the URI itself.
  */
 function isSpaceUri(input) {
-    if (typeof input !== 'string')
-        return false;
-    if (!input.startsWith('at://'))
-        return false;
-    const pathStart = input.indexOf('/', 5); // after "at://"
-    if (pathStart === -1)
-        return false;
-    const rest = input.slice(pathStart + 1);
-    return rest === SPACE_MARKER || rest.startsWith(`${SPACE_MARKER}/`);
+    return typeof input === 'string' && input.startsWith(SPACE_URI_PREFIX);
 }
 /** Whether a string is a valid ATURI addressing public repo data. */
 export function isPublicAtUriString(input, options) {
@@ -275,4 +266,3 @@ function parsePercentEncoding(value) {
         return failure('Invalid percent-encoding');
     }
 }
-//# sourceMappingURL=aturi_validation.js.map