X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=client%2Fsrc%2Fapp%2Fcore%2Frest%2Frest.service.ts;h=4f1fc884846f636b6f4baee4c8738b5394c57681;hb=66357162f8e1227495f09bd4f68446aad7071c6d;hp=78558851a79fff2d3c6e4d95c41f205d1f3ef0fd;hpb=67ed6552b831df66713bac9e672738796128d33f;p=github%2FChocobozzz%2FPeerTube.git diff --git a/client/src/app/core/rest/rest.service.ts b/client/src/app/core/rest/rest.service.ts index 78558851a..4f1fc8848 100644 --- a/client/src/app/core/rest/rest.service.ts +++ b/client/src/app/core/rest/rest.service.ts @@ -9,11 +9,12 @@ interface QueryStringFilterPrefixes { prefix: string handler?: (v: string) => string | number multiple?: boolean + isBoolean?: boolean } } type ParseQueryStringFilterResult = { - [key: string]: string | number | (string | number)[] + [key: string]: string | number | boolean | (string | number | boolean)[] } @Injectable() @@ -48,7 +49,7 @@ export class RestService { const value = object[name] if (value === undefined || value === null) continue - if (Array.isArray(value) && value.length !== 0) { + if (Array.isArray(value)) { for (const v of value) params = params.append(name, v) } else { params = params.append(name, value) @@ -68,8 +69,9 @@ export class RestService { parseQueryStringFilter (q: string, prefixes: QueryStringFilterPrefixes): ParseQueryStringFilterResult { if (!q) return {} - // Tokenize the strings using spaces - const tokens = q.split(' ').filter(token => !!token) + // Tokenize the strings using spaces that are not in quotes + const tokens = q.match(/(?:[^\s"]+|"[^"]*")+/g) + .filter(token => !!token) // Build prefix array const prefixeStrings = Object.values(prefixes) @@ -88,12 +90,14 @@ export class RestService { const matchedTokens = tokens.filter(t => t.startsWith(prefix)) .map(t => t.slice(prefix.length)) // Keep the value filter + .map(t => t.replace(/^"|"$/g, '')) .map(t => { if (prefixObj.handler) return prefixObj.handler(t) return t }) .filter(t => !!t || t === 0) + .map(t => prefixObj.isBoolean ? t === 'true' : t) if (matchedTokens.length === 0) continue