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

Commit

Permalink
fix(interpolate): escape double quotes, etc. in non-mustache text
Browse files Browse the repository at this point in the history
Closes #951
  • Loading branch information
chirayuk committed Apr 23, 2014
1 parent c6be443 commit 3aebb38
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 3 deletions.
4 changes: 2 additions & 2 deletions lib/core/interpolate.dart
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ class Interpolate implements Function {
if (index < startIdx) {
// Empty strings could be stripped thanks to the stringify
// formatter
expParts.add('"${template.substring(index, startIdx)}"');
expParts.add(JSON.encode(template.substring(index, startIdx)));
}
expParts.add('(' + template.substring(startIdx + startLen, endIdx) +
'|stringify)');
Expand All @@ -58,7 +58,7 @@ class Interpolate implements Function {
hasInterpolation = true;
} else {
// we did not find any interpolation, so add the remainder
expParts.add('"${template.substring(index)}"');
expParts.add(JSON.encode(template.substring(index)));
break;
}
}
Expand Down
1 change: 1 addition & 0 deletions lib/core/module_internal.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ library angular.core_internal;

import 'dart:async' as async;
import 'dart:collection';
import 'dart:convert';
import 'dart:math';
import 'package:intl/intl.dart';

Expand Down
8 changes: 7 additions & 1 deletion test/core/interpolate_spec.dart
Original file line number Diff line number Diff line change
Expand Up @@ -33,5 +33,11 @@ main() {
.toEqual('"X\nY"+(A\n+B|stringify)+"C\nD"');
});

it('should not be confused by double quotes, etc. outside mustache',
(Interpolate interpolate) {
expect(interpolate('"{{A}}"'))
.toEqual(r'"\""+(A|stringify)+"\""');
});

});
}
}

2 comments on commit 3aebb38

@jbdeboer
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@vicb
Copy link
Contributor

@vicb vicb commented on 3aebb38 Apr 24, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This had just been merged (see #944 by @vsavkin). I like the JSON.encode trick.

Please sign in to comment.