Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -582,7 +582,7 @@ export abstract class BaseQueryBuilderService {
*/
encodeQuery() {
try {
this.encodedQuery = btoa(JSON.stringify(this.filterRawParams));
this.encodedQuery = btoa(String.fromCharCode(...new TextEncoder().encode(JSON.stringify(this.filterRawParams))));
} catch (error) {
console.error('Failed to encode query parameters:', error);
this.encodedQuery = '';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,18 @@ import { SearchHeaderQueryBuilderService } from './search-header-query-builder.s
import { TestBed } from '@angular/core/testing';
import { ContentTestingModule } from '../../testing/content.testing.module';
import { AlfrescoApiService } from '../../services/alfresco-api.service';
import { ActivatedRoute, Router } from '@angular/router';

describe('SearchHeaderQueryBuilderService', () => {
let activatedRoute: ActivatedRoute;
let router: Router;

beforeEach(() => {
TestBed.configureTestingModule({
imports: [ContentTestingModule]
});
router = TestBed.inject(Router);
activatedRoute = TestBed.inject(ActivatedRoute);
});

const buildConfig = (searchSettings): AppConfigService => {
Expand Down Expand Up @@ -142,4 +148,43 @@ describe('SearchHeaderQueryBuilderService', () => {
expect(searchHeaderService.activeFilters.length).toBe(1);
});
});

describe('updateSearchQueryParams', () => {
it('should use properly encoded query containing non-latin character when calls router.navigate', () => {
spyOn(router, 'navigate');
spyOn(console, 'error');
const service = TestBed.inject(SearchHeaderQueryBuilderService);
service.filterRawParams = { userQuery: '((cm:name:"wąż*" OR cm:title:"wąż*" OR cm:description:"wąż*" OR TEXT:"wąż*" OR TAG:"wąż*"))' };

service.updateSearchQueryParams();
expect(console.error).not.toHaveBeenCalled();
expect(router.navigate).toHaveBeenCalledWith([], {
relativeTo: activatedRoute,
queryParams: {
q: 'eyJ1c2VyUXVlcnkiOiIoKGNtOm5hbWU6XCJ3xIXFvCpcIiBPUiBjbTp0aXRsZTpcInfEhcW8KlwiIE9SIGNtOmRlc2NyaXB0aW9uOlwid8SFxbwqXCIgT1IgVEVYVDpcInfEhcW8KlwiIE9SIFRBRzpcInfEhcW8KlwiKSkifQ=='
},
queryParamsHandling: 'merge'
});
});
});

describe('navigateToSearch', () => {
it('should use properly encoded query containing non-latin character when calls router.navigate', async () => {
spyOn(router, 'navigate');
spyOn(console, 'error');
const searchUrl = 'search';
const service = TestBed.inject(SearchHeaderQueryBuilderService);
service.filterRawParams = { userQuery: '((cm:name:"wąż*" OR cm:title:"wąż*" OR cm:description:"wąż*" OR TEXT:"wąż*" OR TAG:"wąż*"))' };
service.encodeQuery();

await service.navigateToSearch('', searchUrl);
expect(console.error).not.toHaveBeenCalled();
expect(router.navigate).toHaveBeenCalledWith([searchUrl], {
queryParams: {
q: 'eyJ1c2VyUXVlcnkiOiIoKGNtOm5hbWU6XCJ3xIXFvCpcIiBPUiBjbTp0aXRsZTpcInfEhcW8KlwiIE9SIGNtOmRlc2NyaXB0aW9uOlwid8SFxbwqXCIgT1IgVEVYVDpcInfEhcW8KlwiIE9SIFRBRzpcInfEhcW8KlwiKSkifQ=='
},
queryParamsHandling: 'merge'
});
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -801,4 +801,43 @@ describe('SearchQueryBuilder', () => {
});
});
});

describe('updateSearchQueryParams', () => {
it('should use properly encoded query containing non-latin character when calls router.navigate', () => {
spyOn(router, 'navigate');
spyOn(console, 'error');
const service = TestBed.inject(SearchQueryBuilderService);
service.filterRawParams = { userQuery: '((cm:name:"wąż*" OR cm:title:"wąż*" OR cm:description:"wąż*" OR TEXT:"wąż*" OR TAG:"wąż*"))' };

service.updateSearchQueryParams();
expect(console.error).not.toHaveBeenCalled();
expect(router.navigate).toHaveBeenCalledWith([], {
relativeTo: activatedRoute,
queryParams: {
q: 'eyJ1c2VyUXVlcnkiOiIoKGNtOm5hbWU6XCJ3xIXFvCpcIiBPUiBjbTp0aXRsZTpcInfEhcW8KlwiIE9SIGNtOmRlc2NyaXB0aW9uOlwid8SFxbwqXCIgT1IgVEVYVDpcInfEhcW8KlwiIE9SIFRBRzpcInfEhcW8KlwiKSkifQ=='
},
queryParamsHandling: 'merge'
});
});
});

describe('navigateToSearch', () => {
it('should use properly encoded query containing non-latin character when calls router.navigate', async () => {
spyOn(router, 'navigate');
spyOn(console, 'error');
const searchUrl = 'search';
const service = TestBed.inject(SearchQueryBuilderService);
service.filterRawParams = { userQuery: '((cm:name:"wąż*" OR cm:title:"wąż*" OR cm:description:"wąż*" OR TEXT:"wąż*" OR TAG:"wąż*"))' };
service.encodeQuery();

await service.navigateToSearch('', searchUrl);
expect(console.error).not.toHaveBeenCalled();
expect(router.navigate).toHaveBeenCalledWith([searchUrl], {
queryParams: {
q: 'eyJ1c2VyUXVlcnkiOiIoKGNtOm5hbWU6XCJ3xIXFvCpcIiBPUiBjbTp0aXRsZTpcInfEhcW8KlwiIE9SIGNtOmRlc2NyaXB0aW9uOlwid8SFxbwqXCIgT1IgVEVYVDpcInfEhcW8KlwiIE9SIFRBRzpcInfEhcW8KlwiKSkifQ=='
},
queryParamsHandling: 'merge'
});
});
});
});