mirror of
https://github.com/morluto/rea.git
synced 2026-11-20 13:45:30 +00:00
fix(android): accept CR line endings in mapping files (#12346)
Co-authored-by: ShuaixinHuang <197200901+ShuaixinHuang@users.noreply.github.com>
This commit is contained in:
1 parent
55719cafb6
commit
06d1e4cecd
2 files changed
+27
-5
No files matched your search
@@ -63,6 +63,22 @@ const method = (
|
||||
return_type = "void",
|
||||
) => ({ class: `${app}.LoginActivity`, name, return_type, parameter_types });
|
||||
|
||||
it.each([
|
||||
["CR", ["\r"]],
|
||||
["CRLF", ["\r\n"]],
|
||||
["mixed", ["\r\n", "\r", "\n"]],
|
||||
] as const)(
|
||||
"preserves mappings and diagnostics with %s line endings",
|
||||
(_label, endings) => {
|
||||
let line = 0;
|
||||
const text = fixture.replaceAll(
|
||||
"\n",
|
||||
() => endings[line++ % endings.length]!,
|
||||
);
|
||||
expect(parse(text)).toEqual(mapping);
|
||||
},
|
||||
);
|
||||
|
||||
it("reports header facts, valid record counts and malformed line samples", () => {
|
||||
expect(mapping.reported).toEqual({
|
||||
compiler: "R8",
|
||||
|
||||
@@ -752,13 +752,19 @@ export const parseProguardMapping = (
|
||||
if (state.indexBytes > state.limits.indexBytes) capacity(state, "index");
|
||||
if (state.headerBytes > state.limits.projectionBytes)
|
||||
capacity(state, "projection");
|
||||
// R8’s BufferedReader-based mapping reader treats CR, LF, and CRLF as
|
||||
// one line ending each. Find boundaries incrementally to keep memory bounded.
|
||||
const lineEnd = /\r\n?|\n/gu;
|
||||
let start = 0;
|
||||
while (start <= text.length && state.failure === undefined) {
|
||||
const newline = text.indexOf("\n", start);
|
||||
const end = newline < 0 ? text.length : newline;
|
||||
parseLine(state, text.slice(start, end), state.line);
|
||||
if (newline < 0) break;
|
||||
start = newline + 1;
|
||||
const newline = lineEnd.exec(text);
|
||||
parseLine(
|
||||
state,
|
||||
text.slice(start, newline?.index ?? text.length),
|
||||
state.line,
|
||||
);
|
||||
if (newline === null) break;
|
||||
start = lineEnd.lastIndex;
|
||||
state.line++;
|
||||
}
|
||||
if (state.failure !== undefined) return err(state.failure);
|
||||
|
||||
Reference in new issue
Block a user