Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 40d9f27

Browse filesBrowse files
committed
fixed escape characters handlining for strings
1 parent f793d71 commit 40d9f27
Copy full SHA for 40d9f27

File tree

Expand file treeCollapse file tree

2 files changed

+29
-12
lines changed
Filter options
Expand file treeCollapse file tree

2 files changed

+29
-12
lines changed

‎src/interpreter.spec.ts

Copy file name to clipboardExpand all lines: src/interpreter.spec.ts
+21-12Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -741,14 +741,15 @@ describe('Interpreter', () => {
741741
it('Import with package loader', async () => {
742742
const interpreter = Interpreter.create();
743743

744-
interpreter.registerPackagesLoader(path =>
745-
(path === 'service'
746-
? {
747-
add: (x: number, y: number): number => x + y,
748-
remove: (x: number, y: number): number => x - y,
749-
times: (x: number, y: number): number => x * y
750-
}
751-
: null) as any
744+
interpreter.registerPackagesLoader(
745+
path =>
746+
(path === 'service'
747+
? {
748+
add: (x: number, y: number): number => x + y,
749+
remove: (x: number, y: number): number => x - y,
750+
times: (x: number, y: number): number => x * y
751+
}
752+
: null) as any
752753
);
753754

754755
interpreter.registerModuleLoader(() => {
@@ -878,7 +879,7 @@ describe('Interpreter', () => {
878879
`;
879880
expect(await interpreter.evalAsync(script)).toBe(5);
880881
expect(interpreter.eval(script)).toBe(5);
881-
});
882+
});
882883

883884
it('chaining calls - object indexer with ?', async () => {
884885
const interpreter = Interpreter.create();
@@ -888,7 +889,7 @@ describe('Interpreter', () => {
888889
`;
889890
expect(await interpreter.evalAsync(script)).toBe(15);
890891
expect(interpreter.eval(script)).toBe(15);
891-
});
892+
});
892893

893894
it('chaining calls - object indexer with ?', async () => {
894895
const interpreter = Interpreter.create();
@@ -898,7 +899,15 @@ describe('Interpreter', () => {
898899
`;
899900
expect(await interpreter.evalAsync(script)).toBe('2nd');
900901
expect(interpreter.eval(script)).toBe('2nd');
901-
});
902+
});
903+
904+
it('string escape chars', async () => {
905+
const interpreter = Interpreter.create();
906+
expect(interpreter.eval('"12\\"34"')).toBe('12"34');
907+
expect(interpreter.eval(`"12\\'34"`)).toBe(`12'34`);
908+
expect(interpreter.eval(`"12\\\34"`)).toBe(`12\\34`);
909+
expect(interpreter.eval('"\\"12\\"34\\""')).toBe('"12"34"');
910+
});
902911

903-
//
912+
//
904913
});

‎src/tokenizer/tokenizer.ts

Copy file name to clipboardExpand all lines: src/tokenizer/tokenizer.ts
+8Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ const SeparatorsMap: Record<string, string[]> = {
2626
']': [']']
2727
};
2828

29+
const escapeChars = ['"', "'", '\\'];
2930
const Keywords: string[] = ['async', 'def', 'for', 'while', 'if', 'return', 'in'];
3031

3132
export class Tokenizer {
@@ -148,6 +149,13 @@ export class Tokenizer {
148149
this.incrementCursor(3);
149150
} else {
150151
while (script[this.incrementCursor()] !== q) {
152+
if (
153+
script[this._cursor] === '\\' &&
154+
escapeChars.indexOf(script[this._cursor + 1]) >= 0
155+
) {
156+
this._cursor++;
157+
}
158+
151159
this.tokenText += script[this._cursor];
152160
if (this._cursor + 1 >= script.length) break;
153161
}

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.