Skip to content

Commit

Permalink
fix: normalize path correctly when creating a new workspace
Browse files Browse the repository at this point in the history
  • Loading branch information
vsavkin committed Oct 27, 2018
1 parent b3b0211 commit 27f9a94
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,11 @@ <h2 mat-dialog-title><span fxFlex>Create a new workspace</span></h2>
<input class="autofocus" (keydown.enter)="stepper.next()" #workspaceNameInput matInput placeholder="my-new-workspace" [formControl]="control"
name="value">
<mat-error *ngIf="control.invalid && control.errors.nameTaken">
{{ ngNewForm.value.path }}/{{ control.value }} already exists
{{ ngNewForm.value.path + "/" + control.value | normalizePath }} already exists
</mat-error>
<mat-icon matSuffix>create_new_folder</mat-icon>
<mat-hint *ngIf="control.value">
Workspace path will be {{ ngNewForm.value.path }}/{{ control.value }}
Workspace path will be {{ ngNewForm.value.path + "/" + control.value | normalizePath }}
</mat-hint>
</mat-form-field>
</div>
Expand Down
1 change: 1 addition & 0 deletions libs/ui/src/lib/normalize-path.pipe.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,6 @@ describe('NormalizePathPipe', () => {
expect(pipe.transform('C:')).toEqual('C:');
expect(pipe.transform('C://')).toEqual('C:');
expect(pipe.transform('C://one/two')).toEqual('C:\\one\\two');
expect(pipe.transform('C:\\one/two')).toEqual('C:\\one\\two');
});
});
17 changes: 14 additions & 3 deletions libs/ui/src/lib/normalize-path.pipe.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,20 @@ import { Pipe, PipeTransform } from '@angular/core';
})
export class NormalizePathPipe implements PipeTransform {
transform(value: string, args?: any): any {
const firstPart = value.split('/')[0];
if (!firstPart) return value;
if (!firstPart.endsWith(':')) return value;
const firstPartIfWin = value.split('\\')[0];
if (firstPartIfWin && firstPartIfWin.endsWith(':')) {
return this.toWin(value);
}

const firstPartIfUnix = value.split('/')[0];
if (firstPartIfUnix && firstPartIfUnix.endsWith(':')) {
return this.toWin(value);
}

return value;
}

private toWin(value: string) {
return value
.replace(new RegExp('/', 'g'), '\\')
.split('\\')
Expand Down

0 comments on commit 27f9a94

Please sign in to comment.