Skip to content
This repository was archived by the owner on Feb 22, 2018. It is now read-only.

Commit 3aebb38

Browse files
committed
fix(interpolate): escape double quotes, etc. in non-mustache text
Closes #951
1 parent c6be443 commit 3aebb38

File tree

3 files changed

+10
-3
lines changed

3 files changed

+10
-3
lines changed

lib/core/interpolate.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ class Interpolate implements Function {
4949
if (index < startIdx) {
5050
// Empty strings could be stripped thanks to the stringify
5151
// formatter
52-
expParts.add('"${template.substring(index, startIdx)}"');
52+
expParts.add(JSON.encode(template.substring(index, startIdx)));
5353
}
5454
expParts.add('(' + template.substring(startIdx + startLen, endIdx) +
5555
'|stringify)');
@@ -58,7 +58,7 @@ class Interpolate implements Function {
5858
hasInterpolation = true;
5959
} else {
6060
// we did not find any interpolation, so add the remainder
61-
expParts.add('"${template.substring(index)}"');
61+
expParts.add(JSON.encode(template.substring(index)));
6262
break;
6363
}
6464
}

lib/core/module_internal.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ library angular.core_internal;
22

33
import 'dart:async' as async;
44
import 'dart:collection';
5+
import 'dart:convert';
56
import 'dart:math';
67
import 'package:intl/intl.dart';
78

test/core/interpolate_spec.dart

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,5 +33,11 @@ main() {
3333
.toEqual('"X\nY"+(A\n+B|stringify)+"C\nD"');
3434
});
3535

36+
it('should not be confused by double quotes, etc. outside mustache',
37+
(Interpolate interpolate) {
38+
expect(interpolate('"{{A}}"'))
39+
.toEqual(r'"\""+(A|stringify)+"\""');
40+
});
41+
3642
});
37-
}
43+
}

0 commit comments

Comments
 (0)