mirror of
https://github.com/denoland/std.git
synced 2024-11-22 04:59:05 +00:00
fix(toml): handle CRLF as newline in parsing multiline string (#3920)
This commit is contained in:
parent
b460c4a017
commit
aff48b2deb
@ -481,8 +481,11 @@ export function MultilineBasicString(
|
||||
return failure();
|
||||
}
|
||||
if (scanner.char() === "\n") {
|
||||
// The first newline is trimmed
|
||||
// The first newline (LF) is trimmed
|
||||
scanner.next();
|
||||
} else if (scanner.slice(0, 2) === "\r\n") {
|
||||
// The first newline (CRLF) is trimmed
|
||||
scanner.next(2);
|
||||
}
|
||||
const acc: string[] = [];
|
||||
while (scanner.slice(0, 3) !== '"""' && !scanner.eof()) {
|
||||
@ -491,6 +494,10 @@ export function MultilineBasicString(
|
||||
scanner.next();
|
||||
scanner.nextUntilChar({ comment: false });
|
||||
continue;
|
||||
} else if (scanner.slice(0, 3) === "\\\r\n") {
|
||||
scanner.next();
|
||||
scanner.nextUntilChar({ comment: false });
|
||||
continue;
|
||||
}
|
||||
const escapedChar = EscapeSequence(scanner);
|
||||
if (escapedChar.ok) {
|
||||
@ -525,8 +532,11 @@ export function MultilineLiteralString(
|
||||
return failure();
|
||||
}
|
||||
if (scanner.char() === "\n") {
|
||||
// The first newline is trimmed
|
||||
// The first newline (LF) is trimmed
|
||||
scanner.next();
|
||||
} else if (scanner.slice(0, 2) === "\r\n") {
|
||||
// The first newline (CRLF) is trimmed
|
||||
scanner.next(2);
|
||||
}
|
||||
const acc: string[] = [];
|
||||
while (scanner.slice(0, 3) !== "'''" && !scanner.eof()) {
|
||||
|
@ -99,6 +99,27 @@ Violets are\\tblue"""`),
|
||||
},
|
||||
});
|
||||
|
||||
Deno.test({
|
||||
name: "[TOML parser] multi-line basic string (CRLF)",
|
||||
fn() {
|
||||
const parse = ParserFactory(MultilineBasicString);
|
||||
assertEquals(
|
||||
parse(`"""\r
|
||||
Roses are red\r
|
||||
Violets are\\tblue"""`),
|
||||
"Roses are red\r\nViolets are\tblue",
|
||||
);
|
||||
assertEquals(
|
||||
parse(`"""\\\r
|
||||
The quick brown \\\r
|
||||
fox jumps over \\\r
|
||||
the lazy dog.\\\r
|
||||
"""`),
|
||||
"The quick brown fox jumps over the lazy dog.",
|
||||
);
|
||||
},
|
||||
});
|
||||
|
||||
Deno.test({
|
||||
name: "[TOML parser] multi-line literal string",
|
||||
fn() {
|
||||
@ -112,6 +133,19 @@ Violets are\\tblue'''`),
|
||||
},
|
||||
});
|
||||
|
||||
Deno.test({
|
||||
name: "[TOML parser] multi-line literal string (CRLF)",
|
||||
fn() {
|
||||
const parse = ParserFactory(MultilineLiteralString);
|
||||
assertEquals(
|
||||
parse(`'''\r
|
||||
Roses are red\r
|
||||
Violets are\\tblue'''`),
|
||||
"Roses are red\r\nViolets are\\tblue",
|
||||
);
|
||||
},
|
||||
});
|
||||
|
||||
Deno.test({
|
||||
name: "[TOML parser] symbols",
|
||||
fn() {
|
||||
|
Loading…
Reference in New Issue
Block a user