diff --git a/atproto/syntax/atidentifier.go b/atproto/syntax/atidentifier.go index 21a0f8879..be5315c3f 100644 --- a/atproto/syntax/atidentifier.go +++ b/atproto/syntax/atidentifier.go @@ -10,6 +10,9 @@ type AtIdentifier struct { } func ParseAtIdentifier(raw string) (*AtIdentifier, error) { + if raw == "" { + return nil, fmt.Errorf("expected AT account identifier, got empty string") + } if strings.HasPrefix(raw, "did:") { did, err := ParseDID(raw) if err != nil { diff --git a/atproto/syntax/cid.go b/atproto/syntax/cid.go index bd2c7a9b3..8f994c876 100644 --- a/atproto/syntax/cid.go +++ b/atproto/syntax/cid.go @@ -16,6 +16,9 @@ type CID string var cidRegex = regexp.MustCompile(`^[a-zA-Z0-9+=]{8,256}$`) func ParseCID(raw string) (CID, error) { + if raw == "" { + return "", fmt.Errorf("expected CID, got empty string") + } if len(raw) > 256 { return "", fmt.Errorf("CID is too long (256 chars max)") } diff --git a/atproto/syntax/datetime.go b/atproto/syntax/datetime.go index 631918e6a..f1a819bc8 100644 --- a/atproto/syntax/datetime.go +++ b/atproto/syntax/datetime.go @@ -24,6 +24,9 @@ type Datetime string var datetimeRegex = regexp.MustCompile(`^[0-9]{4}-[01][0-9]-[0-3][0-9]T[0-2][0-9]:[0-6][0-9]:[0-6][0-9](.[0-9]{1,20})?(Z|([+-][0-2][0-9]:[0-5][0-9]))$`) func ParseDatetime(raw string) (Datetime, error) { + if raw == "" { + return "", fmt.Errorf("expected datetime, got empty string") + } if len(raw) > 64 { return "", fmt.Errorf("Datetime too long (max 64 chars)") } diff --git a/atproto/syntax/did.go b/atproto/syntax/did.go index 567c58ede..d356dc4fe 100644 --- a/atproto/syntax/did.go +++ b/atproto/syntax/did.go @@ -16,6 +16,9 @@ type DID string var didRegex = regexp.MustCompile(`^did:[a-z]+:[a-zA-Z0-9._:%-]*[a-zA-Z0-9._-]$`) func ParseDID(raw string) (DID, error) { + if raw == "" { + return "", fmt.Errorf("expected DID, got empty string") + } if len(raw) > 2*1024 { return "", fmt.Errorf("DID is too long (2048 chars max)") } diff --git a/atproto/syntax/handle.go b/atproto/syntax/handle.go index 63322b7fc..2c52f9dbe 100644 --- a/atproto/syntax/handle.go +++ b/atproto/syntax/handle.go @@ -21,6 +21,9 @@ var ( type Handle string func ParseHandle(raw string) (Handle, error) { + if raw == "" { + return "", fmt.Errorf("expected handle, got empty string") + } if len(raw) > 253 { return "", fmt.Errorf("handle is too long (253 chars max)") } diff --git a/atproto/syntax/language.go b/atproto/syntax/language.go index 0d263eec6..f65683d27 100644 --- a/atproto/syntax/language.go +++ b/atproto/syntax/language.go @@ -15,6 +15,9 @@ type Language string var langRegex = regexp.MustCompile(`^(i|[a-z]{2,3})(-[a-zA-Z0-9]+)*$`) func ParseLanguage(raw string) (Language, error) { + if raw == "" { + return "", fmt.Errorf("expected language code, got empty string") + } if len(raw) > 128 { return "", fmt.Errorf("Language is too long (128 chars max)") } diff --git a/atproto/syntax/nsid.go b/atproto/syntax/nsid.go index a87778eba..9b0279265 100644 --- a/atproto/syntax/nsid.go +++ b/atproto/syntax/nsid.go @@ -16,6 +16,9 @@ var nsidRegex = regexp.MustCompile(`^[a-zA-Z]([a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(\. type NSID string func ParseNSID(raw string) (NSID, error) { + if raw == "" { + return "", fmt.Errorf("expected NSID, got empty string") + } if len(raw) > 317 { return "", fmt.Errorf("NSID is too long (317 chars max)") } diff --git a/atproto/syntax/recordkey.go b/atproto/syntax/recordkey.go index 24606803b..541a99c38 100644 --- a/atproto/syntax/recordkey.go +++ b/atproto/syntax/recordkey.go @@ -15,6 +15,9 @@ var recordKeyRegex = regexp.MustCompile(`^[a-zA-Z0-9_~.:-]{1,512}$`) type RecordKey string func ParseRecordKey(raw string) (RecordKey, error) { + if raw == "" { + return "", fmt.Errorf("expected record key, got empty string") + } if len(raw) > 512 { return "", fmt.Errorf("recordkey is too long (512 chars max)") } diff --git a/atproto/syntax/tid.go b/atproto/syntax/tid.go index c67b4b216..53a131482 100644 --- a/atproto/syntax/tid.go +++ b/atproto/syntax/tid.go @@ -27,6 +27,9 @@ type TID string var tidRegex = regexp.MustCompile(`^[234567abcdefghij][234567abcdefghijklmnopqrstuvwxyz]{12}$`) func ParseTID(raw string) (TID, error) { + if raw == "" { + return "", fmt.Errorf("expected TID, got empty string") + } if len(raw) != 13 { return "", fmt.Errorf("TID is wrong length (expected 13 chars)") } diff --git a/atproto/syntax/uri.go b/atproto/syntax/uri.go index d2cc6ce7e..4b069d3cc 100644 --- a/atproto/syntax/uri.go +++ b/atproto/syntax/uri.go @@ -13,6 +13,9 @@ import ( type URI string func ParseURI(raw string) (URI, error) { + if raw == "" { + return "", fmt.Errorf("expected URI, got empty string") + } if len(raw) > 8192 { return "", fmt.Errorf("URI is too long (8192 chars max)") }