Skip to content

Commit f888f25

Browse files
committed
fix string parameter
1 parent 2e0b139 commit f888f25

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

src/utils.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ class CSInterface extends CSInterfaceBase {
1616
*
1717
* @return {Promise<*>}
1818
*/
19+
// TODO: Generic function evalScript<T extends (...args: any[]) => any>(script: string, ...args: Parameters<T>): void
1920
evalScript(script: string, ...args: unknown[]): Promise<any>;
2021
evalScript(script: string, callback?: (result?: any) => void): Promise<any> {
2122
/**
@@ -27,7 +28,12 @@ class CSInterface extends CSInterfaceBase {
2728
case 'undefined':
2829
return '"null"';
2930
case 'string':
30-
return JSON.stringify(value);
31+
let str = JSON.stringify(value);
32+
if (str.substr(0,1) !== '"' || str.substr(-1) !== '"') {
33+
throw TypeError(`Unbekannter JSON String: "${str}"`);
34+
}
35+
36+
return `"\\${str.substr(0, str.length -1)}\\""`;
3137
case 'number': {
3238

3339
if (Number.isNaN(value) || Infinity === value) {
@@ -47,7 +53,7 @@ class CSInterface extends CSInterfaceBase {
4753
return value;
4854
}
4955
default:
50-
throw Error(`Nicht unterstützter Typ "${typeof value}"`);
56+
throw TypeError(`Nicht unterstützter Typ "${typeof value}"`);
5157
}
5258
}
5359

@@ -90,6 +96,7 @@ class CSInterface extends CSInterfaceBase {
9096
'{"error": "' + e.name + '", "message": "' + e.message.replace(/"/g, \"'\") + '", "line": "' + (e.line ? e.line - 1: -1) + '", "stack": "' + (e.stack ? e.stack.replace(/"/g, \"'\") : \"\") + '"}'
9197
}`;
9298

99+
console.debug(script);
93100
super.evalScript(script, (result: any) => {
94101

95102
// Wenn der Nutzer eine eigene Callback angegeben hat (evalScript legacy support)

0 commit comments

Comments
 (0)