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

Commit d704313

Browse files
committed
fix(interpolate): Interpolation should use toString instead of json.stringify
Closes #60
1 parent 302d9c6 commit d704313

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

lib/interpolate.dart

+2-2
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ num endSymbolLength = endSymbol.length;
99
class Interpolate {
1010
Parser $parse;
1111
ExceptionHandler $exceptionHandler;
12-
12+
1313
Interpolate(Parser this.$parse, ExceptionHandler this.$exceptionHandler);
1414

1515
ParsedFn call(String text, [bool mustHaveExpression = false]) {
@@ -54,7 +54,7 @@ class Interpolate {
5454
if (chunk == null) {
5555
chunk = '';
5656
} else if (!(chunk is String)) {
57-
chunk = toJson(chunk);
57+
chunk = '$chunk';
5858
}
5959
}
6060
concat.add(chunk);

test/interpolate_spec.dart

+9
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
import "_specs.dart";
22

3+
class ToStringableObject {
4+
toString() => 'World';
5+
}
6+
37
main() {
48
describe('\$interpolate', () {
59

@@ -48,6 +52,11 @@ main() {
4852
expect($interpolate("Hello {{'World' + foo()}}")($rootScope)).toEqual('Hello World');
4953
}));
5054

55+
it('should use toString to conver objects to string', inject((Interpolate $interpolate, Scope $rootScope) {
56+
$rootScope.obj = new ToStringableObject();
57+
expect($interpolate("Hello, {{obj}}!")($rootScope)).toEqual('Hello, World!');
58+
}));
59+
5160

5261
describe('parseBindings', () {
5362
it('should Parse Text With No Bindings', inject((Interpolate $interpolate) {

0 commit comments

Comments
 (0)