Skip to content

Commit 62ecc83

Browse files
authored
Merge pull request #525 from ozmar-11/enhancement/add-trailing-slash
Validate if trailing slash is required
2 parents ea67b95 + c47266d commit 62ecc83

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
@@ -431,15 +431,21 @@ export class AngularTokenService implements CanActivate {
431431
return (this.userType.value == null) ? '' : this.userType.value.path + '/';
432432
}
433433

434+
private addTrailingSlashIfNeeded(url: string): string {
435+
const lastChar = url[url.length - 1];
436+
437+
return lastChar === '/' ? url : url + '/';
438+
}
439+
434440
private getApiPath(): string {
435441
let constructedPath = '';
436442

437443
if (this.options.apiBase != null) {
438-
constructedPath += this.options.apiBase + '/';
444+
constructedPath += this.addTrailingSlashIfNeeded(this.options.apiBase);
439445
}
440446

441447
if (this.options.apiPath != null) {
442-
constructedPath += this.options.apiPath + '/';
448+
constructedPath += this.addTrailingSlashIfNeeded(this.options.apiPath);
443449
}
444450

445451
return constructedPath;

0 commit comments

Comments
 (0)