Skip to content

Commit c47266d

Browse files
committed
Validate if trailing slash is required
- Create the addTrailingSlashIfNeeded method to add the trailing slash only if needed
1 parent 15c38c0 commit c47266d

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

projects/angular-token/src/lib/angular-token.service.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -428,15 +428,21 @@ export class AngularTokenService implements CanActivate {
428428
return (this.userType.value == null) ? '' : this.userType.value.path + '/';
429429
}
430430

431+
private addTrailingSlashIfNeeded(url: string): string {
432+
const lastChar = url[url.length - 1];
433+
434+
return lastChar === '/' ? url : url + '/';
435+
}
436+
431437
private getApiPath(): string {
432438
let constructedPath = '';
433439

434440
if (this.options.apiBase != null) {
435-
constructedPath += this.options.apiBase + '/';
441+
constructedPath += this.addTrailingSlashIfNeeded(this.options.apiBase);
436442
}
437443

438444
if (this.options.apiPath != null) {
439-
constructedPath += this.options.apiPath + '/';
445+
constructedPath += this.addTrailingSlashIfNeeded(this.options.apiPath);
440446
}
441447

442448
return constructedPath;

0 commit comments

Comments
 (0)