Skip to content

Commit

Permalink
unicode fixes (#51)
Browse files Browse the repository at this point in the history
  • Loading branch information
ebauman authored Apr 19, 2020
1 parent 2f456c4 commit 0702e43
Show file tree
Hide file tree
Showing 8 changed files with 36 additions and 22 deletions.
3 changes: 2 additions & 1 deletion src/app/atob.pipe.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { Pipe, PipeTransform } from '@angular/core';
import { atou } from './unicode';

@Pipe({
name: 'atob'
Expand All @@ -7,7 +8,7 @@ export class AtobPipe implements PipeTransform {

transform(value: any, args?: any): any {
if (value) {
return atob(value);
return atou(value);
}
}

Expand Down
7 changes: 4 additions & 3 deletions src/app/data/course.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { map } from 'rxjs/operators';
import { Course } from './course';
import { Scenario } from './scenario';
import { ScenarioService } from './scenario.service';
import { atou } from '../unicode';

@Injectable({
providedIn: 'root'
Expand All @@ -21,7 +22,7 @@ export class CourseService {
return this.http.get(environment.server + "/course/list")
.pipe(
map((s: ServerResponse) => {
let obj: Course[] = JSON.parse(atob(s.content)); // this doesn't encode a map though
let obj: Course[] = JSON.parse(atou(s.content)); // this doesn't encode a map though
// so now we need to go vmset-by-vmset and build maps
obj.forEach((c: Course) => {
c.virtualmachines.forEach((v: Object) => {
Expand All @@ -37,8 +38,8 @@ export class CourseService {
}),
map((cList: Course[]) => {
cList.forEach((c: Course) => {
c.name = atob(c.name);
c.description = atob(c.description);
c.name = atou(c.name);
c.description = atou(c.description);
});
return cList;
})
Expand Down
5 changes: 3 additions & 2 deletions src/app/data/environment.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { ServerResponse } from './serverresponse';
import { formatDate } from '@angular/common';
import { EnvironmentAvailability } from './environmentavailability';
import { Environment } from './environment';
import { atou } from '../unicode';

@Injectable({
providedIn: 'root'
Expand All @@ -19,7 +20,7 @@ export class EnvironmentService {
public list() {
return this.http.get(environment.server + "/a/environment/list")
.pipe(
map((s: ServerResponse) => JSON.parse(atob(s.content)))
map((s: ServerResponse) => JSON.parse(atou(s.content)))
)
}

Expand All @@ -33,7 +34,7 @@ export class EnvironmentService {

return this.http.post(environment.server + "/a/environment/" + env + "/available", params)
.pipe(
map((s: ServerResponse) => JSON.parse(atob(s.content))),
map((s: ServerResponse) => JSON.parse(atou(s.content))),
map((ea: EnvironmentAvailability) => {
ea.environment = env;
return ea;
Expand Down
19 changes: 10 additions & 9 deletions src/app/data/scenario.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { map } from 'rxjs/operators';
import { Scenario } from './scenario';
import { Step } from './step';
import { deepCopy } from '../deepcopy';
import { atou } from '../unicode';

class CustomEncoder implements HttpParameterCodec {
encodeKey(key: string): string {
Expand Down Expand Up @@ -38,7 +39,7 @@ export class ScenarioService {
return this.http.get(environment.server + "/a/scenario/list")
.pipe(
map((s: ServerResponse) => {
let obj: Scenario[] = JSON.parse(atob(s.content)); // this doesn't encode a map though
let obj: Scenario[] = JSON.parse(atou(s.content)); // this doesn't encode a map though
// so now we need to go vmset-by-vmset and build maps
obj.forEach((s: Scenario) => {
s.virtualmachines.forEach((v: Object) => {
Expand All @@ -49,8 +50,8 @@ export class ScenarioService {
}),
map((sList: Scenario[]) => {
sList.forEach((s: Scenario) => {
s.name = atob(s.name);
s.description = atob(s.description);
s.name = atou(s.name);
s.description = atou(s.description);
});
return sList;
})
Expand All @@ -61,15 +62,15 @@ export class ScenarioService {
return this.http.get(environment.server + "/a/scenario/" + id)
.pipe(
map((s: ServerResponse) => {
return JSON.parse(atob(s.content))
return JSON.parse(atou(s.content))
}),
map((s: Scenario) => {
// atob all the relevant fields
s.name = atob(s.name);
s.description = atob(s.description);
// atou all the relevant fields
s.name = atou(s.name);
s.description = atou(s.description);
s.steps.forEach((st: Step) => {
st.content = atob(st.content);
st.title = atob(st.title);
st.content = atou(st.content);
st.title = atou(st.title);
});
return s;
})
Expand Down
11 changes: 6 additions & 5 deletions src/app/data/scheduledevent.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { ServerResponse } from './serverresponse';
import { map, switchMap, combineAll } from 'rxjs/operators';
import { from, of } from 'rxjs';
import { formatDate } from '@angular/common';
import { atou } from '../unicode';

@Injectable({
providedIn: 'root'
Expand All @@ -20,7 +21,7 @@ export class ScheduledeventService {
return this.http.get(environment.server + "/a/scheduledevent/list")
.pipe(
switchMap((s: ServerResponse) => {
return from(JSON.parse(atob(s.content)))
return from(JSON.parse(atou(s.content)))
}),
map((se: ScheduledEvent) => {
se.start_time = new Date(se.start_time);
Expand Down Expand Up @@ -51,7 +52,7 @@ export class ScheduledeventService {
return this.http.post(environment.server + "/a/scheduledevent/new", params)
.pipe(
switchMap((s: ServerResponse) => {
return from(JSON.parse(atob(s.message)))
return from(JSON.parse(atou(s.message)))
})
)
}
Expand All @@ -75,7 +76,7 @@ export class ScheduledeventService {
return this.http.put(environment.server + "/a/scheduledevent/" + se.id, params)
.pipe(
switchMap((s: ServerResponse) => {
return from(JSON.parse(atob(s.message)))
return from(JSON.parse(atou(s.message)))
})
)
}
Expand All @@ -84,7 +85,7 @@ export class ScheduledeventService {
return this.http.delete(environment.server + "/a/scheduledevent/delete/" + se.id)
.pipe(
switchMap((s: ServerResponse) => {
return from(JSON.parse(atob(s.message)))
return from(JSON.parse(atou(s.message)))
})
)
}
Expand All @@ -93,7 +94,7 @@ export class ScheduledeventService {
return this.http.get(environment.server + "/a/scheduledevent/" + id)
.pipe(
switchMap((s: ServerResponse) => {
let se = JSON.parse(atob(s.content));
let se = JSON.parse(atou(s.content));
se.start_time = new Date(se.start_time);
se.end_time = new Date(se.end_time);
return of(se);
Expand Down
3 changes: 2 additions & 1 deletion src/app/data/user.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { switchMap, catchError } from 'rxjs/operators';
import { ServerResponse } from './serverresponse';
import { of, throwError } from 'rxjs';
import { parseTemplate } from '@angular/compiler';
import { atou } from '../unicode';

@Injectable({
providedIn: 'root'
Expand All @@ -20,7 +21,7 @@ export class UserService {
return this.http.get(environment.server + "/a/user/list")
.pipe(
switchMap((s: ServerResponse) => {
return of(JSON.parse(atob(s.content)));
return of(JSON.parse(atou(s.content)));
}),
catchError((e: HttpErrorResponse) => {
return throwError(e.error);
Expand Down
3 changes: 2 additions & 1 deletion src/app/data/vmtemplate.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { environment } from 'src/environments/environment';
import { switchMap } from 'rxjs/operators';
import { ServerResponse } from './serverresponse';
import { of } from 'rxjs';
import { atou } from '../unicode';

@Injectable({
providedIn: 'root'
Expand All @@ -18,7 +19,7 @@ export class VmtemplateService {
return this.http.get(environment.server + '/a/vmtemplate/list')
.pipe(
switchMap((s: ServerResponse) => {
return of(JSON.parse(atob(s.content)))
return of(JSON.parse(atou(s.content)))
})
)
}
Expand Down
7 changes: 7 additions & 0 deletions src/app/unicode.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
export function atou(b64) {
return decodeURIComponent(escape(atob(b64)));
}

export function utoa(data) {
return btoa(unescape(encodeURIComponent(data)));
}

0 comments on commit 0702e43

Please sign in to comment.