From ff1ea804c9408fb7b7a1a2361eb34c386dddf260 Mon Sep 17 00:00:00 2001 From: Marie Verdonck Date: Thu, 13 Oct 2022 14:02:40 +0200 Subject: [PATCH 1/2] 95648: Issue 1900 - URl encode/escape prefix value in facets endpoint --- src/app/core/shared/search/search.service.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/app/core/shared/search/search.service.ts b/src/app/core/shared/search/search.service.ts index 75723366bc..d3cca3dc90 100644 --- a/src/app/core/shared/search/search.service.ts +++ b/src/app/core/shared/search/search.service.ts @@ -376,7 +376,7 @@ export class SearchService implements OnDestroy { let href; const args: string[] = [`page=${valuePage - 1}`, `size=${filterConfig.pageSize}`]; if (hasValue(filterQuery)) { - args.push(`prefix=${filterQuery}`); + args.push(`prefix=${encodeURIComponent(filterQuery)}`); } if (hasValue(searchOptions)) { href = searchOptions.toRestUrl(filterConfig._links.self.href, args); From 595c3175d313246844cd6f6c030041ebfea46d46 Mon Sep 17 00:00:00 2001 From: Alexandre Vryghem Date: Wed, 19 Oct 2022 21:07:15 +0200 Subject: [PATCH 2/2] 95915: Added spec test --- .../core/shared/search/search.service.spec.ts | 34 ++++++++++++++----- 1 file changed, 26 insertions(+), 8 deletions(-) diff --git a/src/app/core/shared/search/search.service.spec.ts b/src/app/core/shared/search/search.service.spec.ts index 00f10230c3..a8a2ed2b83 100644 --- a/src/app/core/shared/search/search.service.spec.ts +++ b/src/app/core/shared/search/search.service.spec.ts @@ -23,11 +23,11 @@ import { RemoteDataBuildService } from '../../cache/builders/remote-data-build.s import { createSuccessfulRemoteDataObject$ } from '../../../shared/remote-data.utils'; import { SearchObjects } from '../../../shared/search/search-objects.model'; import { PaginationService } from '../../pagination/pagination.service'; -import { PaginationComponentOptions } from '../../../shared/pagination/pagination-component-options.model'; -import { SortDirection, SortOptions } from '../../cache/models/sort-options.model'; -import { FindListOptions } from '../../data/request.models'; import { SearchConfigurationService } from './search-configuration.service'; import { PaginationServiceStub } from '../../../shared/testing/pagination-service.stub'; +import { SearchFilterConfig } from '../../../shared/search/search-filter-config.model'; +import { GetRequest } from '../../data/request.models'; +import anything = jasmine.anything; @Component({ template: '' }) class DummyComponent { @@ -38,7 +38,7 @@ describe('SearchService', () => { let searchService: SearchService; const router = new RouterStub(); const route = new ActivatedRouteStub(); - const searchConfigService = {paginationID: 'page-id'}; + const searchConfigService = { paginationID: 'page-id' }; beforeEach(() => { TestBed.configureTestingModule({ imports: [ @@ -104,7 +104,8 @@ describe('SearchService', () => { }; const paginationService = new PaginationServiceStub(); - const searchConfigService = {paginationID: 'page-id'}; + const searchConfigService = { paginationID: 'page-id' }; + const requestService = getMockRequestService(); beforeEach(() => { TestBed.configureTestingModule({ @@ -120,7 +121,7 @@ describe('SearchService', () => { providers: [ { provide: Router, useValue: router }, { provide: RouteService, useValue: routeServiceStub }, - { provide: RequestService, useValue: getMockRequestService() }, + { provide: RequestService, useValue: requestService }, { provide: RemoteDataBuildService, useValue: remoteDataBuildService }, { provide: HALEndpointService, useValue: halService }, { provide: CommunityDataService, useValue: {} }, @@ -138,13 +139,13 @@ describe('SearchService', () => { it('should call the navigate method on the Router with view mode list parameter as a parameter when setViewMode is called', () => { searchService.setViewMode(ViewMode.ListElement); - expect(paginationService.updateRouteWithUrl).toHaveBeenCalledWith('page-id', ['/search'], {page: 1}, { view: ViewMode.ListElement } + expect(paginationService.updateRouteWithUrl).toHaveBeenCalledWith('page-id', ['/search'], { page: 1 }, { view: ViewMode.ListElement } ); }); it('should call the navigate method on the Router with view mode grid parameter as a parameter when setViewMode is called', () => { searchService.setViewMode(ViewMode.GridElement); - expect(paginationService.updateRouteWithUrl).toHaveBeenCalledWith('page-id', ['/search'], {page: 1}, { view: ViewMode.GridElement } + expect(paginationService.updateRouteWithUrl).toHaveBeenCalledWith('page-id', ['/search'], { page: 1 }, { view: ViewMode.GridElement } ); }); @@ -290,5 +291,22 @@ describe('SearchService', () => { }); }); + describe('when getFacetValuesFor is called with a filterQuery', () => { + it('should add the encoded filterQuery to the args list', () => { + jasmine.getEnv().allowRespy(true); + const spyRequest = spyOn((searchService as any), 'request').and.stub(); + spyOn(requestService, 'send').and.returnValue(true); + const searchFilterConfig = new SearchFilterConfig(); + searchFilterConfig._links = { + self: { + href: 'https://demo.dspace.org/', + }, + }; + + searchService.getFacetValuesFor(searchFilterConfig, 1, undefined, 'filter&Query'); + + expect(spyRequest).toHaveBeenCalledWith(anything(), 'https://demo.dspace.org?page=0&size=5&prefix=filter%26Query'); + }); + }); }); });