Skip to content

Commit 95a848a

Browse files
authored
Merge pull request DSpace#1919 from atmire/w2p-95648_issue-1900_facet-prefix-values-not-escaped_latest
Search in sidebar/facet don't escape special characters
2 parents 8305032 + d832fa3 commit 95a848a

2 files changed

Lines changed: 27 additions & 6 deletions

File tree

src/app/core/shared/search/search.service.spec.ts

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ import { SearchConfigurationService } from './search-configuration.service';
2626
import { PaginationServiceStub } from '../../../shared/testing/pagination-service.stub';
2727
import { RequestEntry } from '../../data/request-entry.model';
2828
import { Angulartics2 } from 'angulartics2';
29+
import { SearchFilterConfig } from '../../../shared/search/models/search-filter-config.model';
30+
import anything = jasmine.anything;
2931

3032
@Component({ template: '' })
3133
class DummyComponent {
@@ -36,7 +38,7 @@ describe('SearchService', () => {
3638
let searchService: SearchService;
3739
const router = new RouterStub();
3840
const route = new ActivatedRouteStub();
39-
const searchConfigService = {paginationID: 'page-id'};
41+
const searchConfigService = { paginationID: 'page-id' };
4042
beforeEach(() => {
4143
TestBed.configureTestingModule({
4244
imports: [
@@ -103,7 +105,8 @@ describe('SearchService', () => {
103105
};
104106

105107
const paginationService = new PaginationServiceStub();
106-
const searchConfigService = {paginationID: 'page-id'};
108+
const searchConfigService = { paginationID: 'page-id' };
109+
const requestService = getMockRequestService();
107110

108111
beforeEach(() => {
109112
TestBed.configureTestingModule({
@@ -119,7 +122,7 @@ describe('SearchService', () => {
119122
providers: [
120123
{ provide: Router, useValue: router },
121124
{ provide: RouteService, useValue: routeServiceStub },
122-
{ provide: RequestService, useValue: getMockRequestService() },
125+
{ provide: RequestService, useValue: requestService },
123126
{ provide: RemoteDataBuildService, useValue: remoteDataBuildService },
124127
{ provide: HALEndpointService, useValue: halService },
125128
{ provide: CommunityDataService, useValue: {} },
@@ -138,13 +141,13 @@ describe('SearchService', () => {
138141

139142
it('should call the navigate method on the Router with view mode list parameter as a parameter when setViewMode is called', () => {
140143
searchService.setViewMode(ViewMode.ListElement);
141-
expect(paginationService.updateRouteWithUrl).toHaveBeenCalledWith('page-id', ['/search'], {page: 1}, { view: ViewMode.ListElement }
144+
expect(paginationService.updateRouteWithUrl).toHaveBeenCalledWith('page-id', ['/search'], { page: 1 }, { view: ViewMode.ListElement }
142145
);
143146
});
144147

145148
it('should call the navigate method on the Router with view mode grid parameter as a parameter when setViewMode is called', () => {
146149
searchService.setViewMode(ViewMode.GridElement);
147-
expect(paginationService.updateRouteWithUrl).toHaveBeenCalledWith('page-id', ['/search'], {page: 1}, { view: ViewMode.GridElement }
150+
expect(paginationService.updateRouteWithUrl).toHaveBeenCalledWith('page-id', ['/search'], { page: 1 }, { view: ViewMode.GridElement }
148151
);
149152
});
150153

@@ -191,5 +194,23 @@ describe('SearchService', () => {
191194
expect((searchService as any).rdb.buildFromHref).toHaveBeenCalledWith(endPoint);
192195
});
193196
});
197+
198+
describe('when getFacetValuesFor is called with a filterQuery', () => {
199+
it('should add the encoded filterQuery to the args list', () => {
200+
jasmine.getEnv().allowRespy(true);
201+
const spyRequest = spyOn((searchService as any), 'request').and.stub();
202+
spyOn(requestService, 'send').and.returnValue(true);
203+
const searchFilterConfig = new SearchFilterConfig();
204+
searchFilterConfig._links = {
205+
self: {
206+
href: 'https://demo.dspace.org/',
207+
},
208+
};
209+
210+
searchService.getFacetValuesFor(searchFilterConfig, 1, undefined, 'filter&Query');
211+
212+
expect(spyRequest).toHaveBeenCalledWith(anything(), 'https://demo.dspace.org?page=0&size=5&prefix=filter%26Query');
213+
});
214+
});
194215
});
195216
});

src/app/core/shared/search/search.service.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -271,7 +271,7 @@ export class SearchService implements OnDestroy {
271271
let href;
272272
let args: string[] = [];
273273
if (hasValue(filterQuery)) {
274-
args.push(`prefix=${filterQuery}`);
274+
args.push(`prefix=${encodeURIComponent(filterQuery)}`);
275275
}
276276
if (hasValue(searchOptions)) {
277277
searchOptions = Object.assign(new PaginatedSearchOptions({}), searchOptions, {

0 commit comments

Comments
 (0)