fix(styles): Escape \r characters in compiled text

Closes #5772

Closes #5835
This commit is contained in:
Tim Blasi 2015-12-11 09:56:50 -08:00 committed by Timothy Blasi
parent 0cb32c2fef
commit 92ddc62bed
2 changed files with 10 additions and 2 deletions

View File

@ -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';
@ -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]}`;
}

View File

@ -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 {
@ -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 {