Skip to content

Commit

Permalink
fix(styles): Escape \r characters in compiled text
Browse files Browse the repository at this point in the history
  • Loading branch information
Tim Blasi committed Dec 11, 2015
1 parent 080469f commit 14b8078
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
6 changes: 4 additions & 2 deletions modules/angular2/src/compiler/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ import {IS_DART, StringWrapper, isBlank} from 'angular2/src/facade/lang';

var CAMEL_CASE_REGEXP = /([A-Z])/g;
var DASH_CASE_REGEXP = /-([a-z])/g;
var SINGLE_QUOTE_ESCAPE_STRING_RE = /'|\\|\n|\$/g;
var DOUBLE_QUOTE_ESCAPE_STRING_RE = /"|\\|\n|\$/g;
var SINGLE_QUOTE_ESCAPE_STRING_RE = /'|\\|\n|\r|\$/g;
var DOUBLE_QUOTE_ESCAPE_STRING_RE = /"|\\|\n|\r|\$/g;

export var MODULE_SUFFIX = IS_DART ? '.dart' : '.js';

Expand Down Expand Up @@ -37,6 +37,8 @@ function escapeString(input: string, re: RegExp): string {
return IS_DART ? '\\$' : '$';
} else if (match[0] == '\n') {
return '\\n';
} else if (match[0] == '\r') {
return '\\r';
} else {
return `\\${match[0]}`;
}
Expand Down
6 changes: 6 additions & 0 deletions modules/angular2/test/compiler/util_spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ export function main() {
it('should escape newlines',
() => { expect(escapeSingleQuoteString('\n')).toEqual(`'\\n'`); });

it('should escape carriage returns',
() => { expect(escapeSingleQuoteString('\r')).toEqual(`'\\r'`); });

if (IS_DART) {
it('should escape $', () => { expect(escapeSingleQuoteString('$')).toEqual(`'\\$'`); });
} else {
Expand All @@ -44,6 +47,9 @@ export function main() {
it('should escape newlines',
() => { expect(escapeDoubleQuoteString('\n')).toEqual(`"\\n"`); });

it('should escape carriage returns',
() => { expect(escapeDoubleQuoteString('\r')).toEqual(`"\\r"`); });

if (IS_DART) {
it('should escape $', () => { expect(escapeDoubleQuoteString('$')).toEqual(`"\\$"`); });
} else {
Expand Down

0 comments on commit 14b8078

Please sign in to comment.