Skip to content

Commit ca0f45d

Browse files
feat: preserve pipe-delimited OR groups in tags DTO
Stop splitting tags on | so that OR-group tokens (e.g. cat|dog) are forwarded intact to the Universal Booru Wrapper, which applies the correct engine-specific OR syntax per booru engine. Pipelines the change through the full stack: App → | (user types 'cat OR dog') API → ['cat|dog'] (kept as OR-group token) Wrapper → '{ ~ cat ~ dog }' (Gelbooru) / '~cat ~dog' (Danbooru/e621)
1 parent 8e8f2ac commit ca0f45d

2 files changed

Lines changed: 11 additions & 11 deletions

File tree

src/booru/dto/booru-queries.dto.spec.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -31,34 +31,34 @@ describe('booruQueryValuesPostsDTO request handling', () => {
3131
await app.close()
3232
})
3333

34-
it('should rely on request parsing for percent-decoding and split tags by pipe', async () => {
34+
it('should rely on request parsing for percent-decoding and preserve comma OR-groups', async () => {
3535
const response = await app.inject({
3636
method: 'GET',
37-
url: '/dto-test/posts?baseEndpoint=gelbooru.com&tags=panty_%26_stocking_with_garterbelt%7Crating%3Asafe'
37+
url: '/dto-test/posts?baseEndpoint=gelbooru.com&tags=panty_%26_stocking_with_garterbelt%2Cblue_hair'
3838
})
3939

4040
const body = JSON.parse(response.body)
4141

4242
expect(response.statusCode).toBe(200)
43-
expect(body.tags).toEqual(['panty_&_stocking_with_garterbelt', 'rating:safe'])
43+
expect(body.tags).toEqual(['panty_&_stocking_with_garterbelt,blue_hair'])
4444
})
4545

46-
it('should normalize repeated tags query params and split each entry', async () => {
46+
it('should normalize repeated tags query params and keep each OR-group token intact', async () => {
4747
const response = await app.inject({
4848
method: 'GET',
49-
url: '/dto-test/posts?baseEndpoint=gelbooru.com&tags=artist%3Afoo%7Crating%3Asafe&tags=score%3A%3E100'
49+
url: '/dto-test/posts?baseEndpoint=gelbooru.com&tags=artist%3Afoo%2Crating%3Asafe&tags=score%3A%3E100'
5050
})
5151

5252
const body = JSON.parse(response.body)
5353

5454
expect(response.statusCode).toBe(200)
55-
expect(body.tags).toEqual(['artist:foo', 'rating:safe', 'score:>100'])
55+
expect(body.tags).toEqual(['artist:foo,rating:safe', 'score:>100'])
5656
})
5757

58-
it('should reject empty tags created after pipe splitting', async () => {
58+
it('should reject empty tags produced by repeated query params', async () => {
5959
const response = await app.inject({
6060
method: 'GET',
61-
url: '/dto-test/posts?baseEndpoint=gelbooru.com&tags=tag1%7C'
61+
url: '/dto-test/posts?baseEndpoint=gelbooru.com&tags=tag1&tags='
6262
})
6363

6464
expect(response.statusCode).toBe(400)

src/booru/dto/booru-queries.dto.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -186,9 +186,9 @@ export class booruQueryValuesPostsDTO extends booruQueriesDTO {
186186
return value
187187
}
188188

189-
return (Array.isArray(value) ? value : [value]).flatMap((tag) =>
190-
typeof tag === 'string' ? tag.trim().split('|') : [tag]
191-
)
189+
return (Array.isArray(value) ? value : [value])
190+
.map((tag) => (typeof tag === 'string' ? tag : String(tag)))
191+
.map((tag) => tag.trim())
192192
})
193193
@IsOptional()
194194
readonly tags: IBooruQueryValues['posts']['tags']

0 commit comments

Comments
 (0)