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:
ShuaixinHuangandShuaixinHuang authored and GitHub committed 2026-11-19 08:31:53 -05:00
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",
+11 -5
View File
@@ -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);