Skip to content

Commit 37726d8

Browse files
committed
feat: support uppercase tag filters (#A-Z) in filter schema
Updates filter-schema.ts validation regex from /^#[a-z]$/ to /^#[a-zA-Z]$/ so uppercase tag filters like #I, #K, #E, #A (used by NIP-22 comment threading) pass validation. Adds unit test covering NIP-22 uppercase tag filter acceptance.
1 parent b09e23a commit 37726d8

2 files changed

Lines changed: 14 additions & 1 deletion

File tree

src/schemas/filter-schema.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ export const filterSchema = z
1616
.catchall(z.array(z.string().min(1).max(1024)))
1717
.superRefine((data, ctx) => {
1818
for (const key of Object.keys(data)) {
19-
if (!knownFilterKeys.has(key) && !/^#[a-z]$/.test(key)) {
19+
if (!knownFilterKeys.has(key) && !/^#[a-zA-Z]$/.test(key)) {
2020
ctx.addIssue({
2121
code: z.ZodIssueCode.custom,
2222
message: `Unknown key: ${key}`,

test/unit/schemas/filter-schema.spec.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,19 @@ describe('NIP-01', () => {
2222
}
2323
})
2424

25+
it('accepts uppercase tag filters (#A-Z)', () => {
26+
const filterWithUppercase = {
27+
...filter,
28+
'#I': ['identifier1', 'identifier2'],
29+
'#K': ['1111'],
30+
'#E': ['aa', 'bb'],
31+
'#A': ['10000:pubkey:dtag'],
32+
}
33+
const result = validateSchema(filterSchema)(filterWithUppercase)
34+
expect(result.error).to.be.undefined
35+
expect(result.value).to.deep.equal(filterWithUppercase)
36+
})
37+
2538
it('returns same filter if filter is valid', () => {
2639
const result = validateSchema(filterSchema)(filter)
2740

0 commit comments

Comments
 (0)