X Tutup
Skip to content

Commit 92ddc62

Browse files
Tim Blasikegluneq
authored andcommitted
fix(styles): Escape \r characters in compiled text
Closes #5772 Closes #5835
1 parent 0cb32c2 commit 92ddc62

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

modules/angular2/src/compiler/util.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ import {IS_DART, StringWrapper, isBlank} from 'angular2/src/facade/lang';
22

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

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

@@ -37,6 +37,8 @@ function escapeString(input: string, re: RegExp): string {
3737
return IS_DART ? '\\$' : '$';
3838
} else if (match[0] == '\n') {
3939
return '\\n';
40+
} else if (match[0] == '\r') {
41+
return '\\r';
4042
} else {
4143
return `\\${match[0]}`;
4244
}

modules/angular2/test/compiler/util_spec.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,9 @@ export function main() {
2727
it('should escape newlines',
2828
() => { expect(escapeSingleQuoteString('\n')).toEqual(`'\\n'`); });
2929

30+
it('should escape carriage returns',
31+
() => { expect(escapeSingleQuoteString('\r')).toEqual(`'\\r'`); });
32+
3033
if (IS_DART) {
3134
it('should escape $', () => { expect(escapeSingleQuoteString('$')).toEqual(`'\\$'`); });
3235
} else {
@@ -44,6 +47,9 @@ export function main() {
4447
it('should escape newlines',
4548
() => { expect(escapeDoubleQuoteString('\n')).toEqual(`"\\n"`); });
4649

50+
it('should escape carriage returns',
51+
() => { expect(escapeDoubleQuoteString('\r')).toEqual(`"\\r"`); });
52+
4753
if (IS_DART) {
4854
it('should escape $', () => { expect(escapeDoubleQuoteString('$')).toEqual(`"\\$"`); });
4955
} else {

0 commit comments

Comments
 (0)
X Tutup