Handle carriage-return only newlines

Newlines are normalised to \r\n, but that previously assumed that only
\r\n and \n newline characters could be used. Even though \r newlines
are rarely used in the wild, it's be helpful to support them. Currently,
they're just removed entirely.
This commit is contained in:
Harry Marr 2015-12-01 21:13:29 +00:00
parent d517017ec0
commit 68d1b5a35c

View File

@ -48,7 +48,7 @@ export default function Literal() {
*/ */
Literal.prototype.setText = function(text) { Literal.prototype.setText = function(text) {
// normalize EOL to \r\n // normalize EOL to \r\n
text = text.replace(/\r/g, '').replace(/\n/g, '\r\n'); text = text.replace(/\r\n/g, '\n').replace(/\r/g, '\n').replace(/\n/g, '\r\n');
// encode UTF8 // encode UTF8
this.data = this.format === 'utf8' ? util.str2Uint8Array(util.encode_utf8(text)) : util.str2Uint8Array(text); this.data = this.format === 'utf8' ? util.str2Uint8Array(util.encode_utf8(text)) : util.str2Uint8Array(text);
}; };