Browse Source

remove duplicate slashes in url (#13409)

pull/13411/head
Muhammed Altuğ 4 years ago
committed by GitHub
parent
commit
5a1b4e1d61
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 8
      npm/ng-packs/packages/core/src/lib/services/rest.service.ts
  2. 13
      npm/ng-packs/packages/core/src/lib/tests/rest.service.spec.ts

8
npm/ng-packs/packages/core/src/lib/services/rest.service.ts

@ -38,9 +38,9 @@ export class RestService {
api = api || this.getApiFromStore(config.apiName);
const { method, params, ...options } = request;
const { observe = Rest.Observe.Body, skipHandleError } = config;
const url = this.removeDuplicateSlashes(api + request.url);
return this.http
.request<R>(method, api + request.url, {
.request<R>(method, url, {
observe,
...(params && {
params: this.getParams(params, config.httpParamEncoder),
@ -62,4 +62,8 @@ export class RestService {
? new HttpParams({ encoder, fromObject: filteredParams })
: new HttpParams({ fromObject: filteredParams });
}
private removeDuplicateSlashes(url: string): string {
return url.replace(/([^:]\/)\/+/g, '$1');
}
}

13
npm/ng-packs/packages/core/src/lib/tests/rest.service.spec.ts

@ -120,4 +120,17 @@ describe('HttpClient testing', () => {
const req = spectator.expectOne(api + '/test', HttpMethod.GET);
spectator.flushAll([req], [throwError('Testing error')]);
});
test('should remove the duplicate slashes', () => {
spectator.service
.request({ method: HttpMethod.GET, url: '//test', params: { id: 1 } })
.subscribe();
spectator.expectOne(api + '/test?id=1', HttpMethod.GET);
});
test('should remove the duplicate slashes multiple', () => {
spectator.service
.request({ method: HttpMethod.GET, url: '//test//my//endpoint', params: { id: 1 } })
.subscribe();
spectator.expectOne(api + '/test/my/endpoint?id=1', HttpMethod.GET);
});
});

Loading…
Cancel
Save