Skip to content

Commit

Permalink
use and improve existing atou and utoa functions for unicode handling…
Browse files Browse the repository at this point in the history
… in course information (#219)

Co-authored-by: Philip Prinz <[email protected]>
  • Loading branch information
PhPrinz and Philip Prinz authored Jun 7, 2024
1 parent 9fb7502 commit 20a0921
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 9 deletions.
10 changes: 5 additions & 5 deletions src/app/data/course.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { map, catchError, tap } from 'rxjs/operators';
import { Course, CourseApi } from './course';
import { Scenario } from './scenario';
import { ScenarioService } from './scenario.service';
import { atou } from '../unicode';
import { atou, utoa } from '../unicode';
import { BehaviorSubject, of, throwError } from 'rxjs';
import { RbacService } from './rbac.service';

Expand Down Expand Up @@ -107,8 +107,8 @@ export class CourseService {
scenarioArray.push(s.id);
});
var params = new HttpParams()
.set('name', btoa(c.name))
.set('description', btoa(c.description))
.set('name', utoa(c.name))
.set('description', utoa(c.description))
.set('keepalive_duration', c.keepalive_duration)
.set('pause_duration', c.pause_duration)
.set('pauseable', JSON.stringify(c.pauseable))
Expand All @@ -124,8 +124,8 @@ export class CourseService {
scenarioArray.push(s.id);
});
var params = new HttpParams()
.set('name', btoa(c.name))
.set('description', btoa(c.description))
.set('name', utoa(c.name))
.set('description', utoa(c.description))
.set('keepalive_duration', c.keepalive_duration)
.set('pause_duration', c.pause_duration)
.set('pauseable', JSON.stringify(c.pauseable))
Expand Down
15 changes: 11 additions & 4 deletions src/app/unicode.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,14 @@
export function atou(b64) {
return decodeURIComponent(escape(atob(b64)));
export function atou(b64Str: string) {
const text = atob(b64Str);
const length = text.length;
const bytes = new Uint8Array(length);
for (let i = 0; i < length; i++) {
bytes[i] = text.charCodeAt(i);
}
const decoder = new TextDecoder(); // default is utf-8
return decoder.decode(bytes);
}

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

0 comments on commit 20a0921

Please sign in to comment.