mirror of
https://github.com/Alfresco/alfresco-ng2-components.git
synced 2026-09-09 18:03:21 +00:00
[ACS-10384] after recent changes search query builder can t process non latin characters (#11241)
* [ACS-10384] Fixed error when using non-latina characters in search * [ACS-10384] Unit tests
This commit is contained in:
@@ -582,7 +582,7 @@ export abstract class BaseQueryBuilderService {
|
|||||||
*/
|
*/
|
||||||
encodeQuery() {
|
encodeQuery() {
|
||||||
try {
|
try {
|
||||||
this.encodedQuery = btoa(JSON.stringify(this.filterRawParams));
|
this.encodedQuery = btoa(String.fromCharCode(...new TextEncoder().encode(JSON.stringify(this.filterRawParams))));
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('Failed to encode query parameters:', error);
|
console.error('Failed to encode query parameters:', error);
|
||||||
this.encodedQuery = '';
|
this.encodedQuery = '';
|
||||||
|
|||||||
+45
@@ -21,12 +21,18 @@ import { SearchHeaderQueryBuilderService } from './search-header-query-builder.s
|
|||||||
import { TestBed } from '@angular/core/testing';
|
import { TestBed } from '@angular/core/testing';
|
||||||
import { ContentTestingModule } from '../../testing/content.testing.module';
|
import { ContentTestingModule } from '../../testing/content.testing.module';
|
||||||
import { AlfrescoApiService } from '../../services/alfresco-api.service';
|
import { AlfrescoApiService } from '../../services/alfresco-api.service';
|
||||||
|
import { ActivatedRoute, Router } from '@angular/router';
|
||||||
|
|
||||||
describe('SearchHeaderQueryBuilderService', () => {
|
describe('SearchHeaderQueryBuilderService', () => {
|
||||||
|
let activatedRoute: ActivatedRoute;
|
||||||
|
let router: Router;
|
||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
TestBed.configureTestingModule({
|
TestBed.configureTestingModule({
|
||||||
imports: [ContentTestingModule]
|
imports: [ContentTestingModule]
|
||||||
});
|
});
|
||||||
|
router = TestBed.inject(Router);
|
||||||
|
activatedRoute = TestBed.inject(ActivatedRoute);
|
||||||
});
|
});
|
||||||
|
|
||||||
const buildConfig = (searchSettings): AppConfigService => {
|
const buildConfig = (searchSettings): AppConfigService => {
|
||||||
@@ -142,4 +148,43 @@ describe('SearchHeaderQueryBuilderService', () => {
|
|||||||
expect(searchHeaderService.activeFilters.length).toBe(1);
|
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'
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -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'
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user