Browse Source

Fix URL encoding for JSON query string parameter

pull/1305/head
Noah 2 months ago
parent
commit
70c2fea7e6
  1. 4
      frontend/src/app/shared/services/contents.service.spec.ts
  2. 2
      frontend/src/app/shared/services/contents.service.ts

4
frontend/src/app/shared/services/contents.service.spec.ts

@ -36,7 +36,7 @@ describe('ContentsService', () => {
name: 'json query',
query: { take: 17, skip: 13, query: { fullText: 'my-query' } },
requestBody: { q: sanitize({ fullText: 'my-query', take: 17, skip: 13 }) },
requestString: `q=${JSON.stringify(sanitize({ fullText: 'my-query', take: 17, skip: 13 }))}`,
requestString: `q=${encodeURIComponent(JSON.stringify(sanitize({ fullText: 'my-query', take: 17, skip: 13 })))}`,
noSlowTotal: null,
noTotal: null,
},
@ -52,7 +52,7 @@ describe('ContentsService', () => {
name: 'json query without total',
query: { take: 17, skip: 13, query: { fullText: 'my-query' }, noTotal: true, noSlowTotal: true },
requestBody: { q: sanitize({ fullText: 'my-query', take: 17, skip: 13 }) },
requestString: `q=${JSON.stringify(sanitize({ fullText: 'my-query', take: 17, skip: 13 }))}`,
requestString: `q=${encodeURIComponent(JSON.stringify(sanitize({ fullText: 'my-query', take: 17, skip: 13 })))}`,
noSlowTotal: '1',
noTotal: '1',
},

2
frontend/src/app/shared/services/contents.service.ts

@ -267,7 +267,7 @@ function buildFullQuery(primary: FullQuery, q?: ContentsByQuery) {
function buildQueryString(input: { q?: object; odata?: string }) {
const { odata, q } = input;
return q ? `?q=${JSON.stringify(q)}` : `?${odata}`;
return q ? `?q=${encodeURIComponent(JSON.stringify(q))}` : `?${odata}`;
}
function buildQuery(q?: ContentsByQuery): { q?: object; odata?: string } {

Loading…
Cancel
Save