mirror of
https://github.com/morluto/rea.git
synced 2026-11-19 13:12:26 +00:00
fix(android): accept R8 mapping separator spacing (#12247)
Co-authored-by: hhang <169027046+xu91102@users.noreply.github.com>
This commit is contained in:
1 parent
a3a7922243
commit
7419328ea7
3 files changed
+106
-15
No files matched your search
@@ -351,7 +351,9 @@ fails explicitly instead of silently truncating facts. MCP refusal includes
|
||||
the retained parent ID. Select complete detail, or inspect one method rather
|
||||
than a whole class, when the requested summary does not fit.
|
||||
|
||||
The mapping path must be absolute. Selectors still take the observed names, such as
|
||||
The mapping path must be absolute. Mapping records accept optional spacing
|
||||
around `->` and spaces or tabs between a member type and its name.
|
||||
Selectors still take the observed names, such as
|
||||
`a.b`, and observed rows are unchanged. The result adds one `mapping` block with
|
||||
the file's path, SHA-256 and size, the header values the file reports
|
||||
(`compiler`, `compiler_version`, `min_api`, `map_version`, `pg_map_id`,
|
||||
|
||||
@@ -641,6 +641,60 @@ it("treats CRLF and tab indentation like LF and spaces", () => {
|
||||
).toEqual(mapping);
|
||||
});
|
||||
|
||||
it.each([
|
||||
["tabs", "\t->\t"],
|
||||
["multiple spaces", " -> "],
|
||||
["no spaces", "->"],
|
||||
["one-sided spacing", "\t->"],
|
||||
] as const)("reads the same mapping when arrows use %s", (_name, arrow) => {
|
||||
expect(parse(fixture.replaceAll(" -> ", arrow))).toEqual(mapping);
|
||||
});
|
||||
|
||||
it("maps fields and methods whose types are separated by tabs", () => {
|
||||
const observed = parse(
|
||||
[
|
||||
"example.Original -> a:",
|
||||
" int\t\tcounter -> c",
|
||||
" 4:4:void\trun():5:5 -> r",
|
||||
].join("\n"),
|
||||
);
|
||||
expect(
|
||||
resolveProguardField(observed, { className: "a", name: "c", type: "I" }),
|
||||
).toMatchObject({ status: "mapped", mapped: { name: "counter" } });
|
||||
expect(
|
||||
resolveProguardMethod(observed, {
|
||||
className: "a",
|
||||
name: "r",
|
||||
descriptor: "()V",
|
||||
}),
|
||||
).toMatchObject({ status: "mapped", mapped: { name: "run" } });
|
||||
});
|
||||
|
||||
it("reports extra mapping arrows on their original source lines", () => {
|
||||
const observed = parse(
|
||||
[
|
||||
"example.Original -> a:",
|
||||
" int count -> c -> other",
|
||||
" void run() -> r -> other",
|
||||
"example.Broken -> b -> other:",
|
||||
" int orphan -> x",
|
||||
"example.Next -> n:",
|
||||
].join("\n"),
|
||||
);
|
||||
expect(observed.records).toEqual({
|
||||
classes: 2,
|
||||
fields: 0,
|
||||
methods: 0,
|
||||
malformed: 4,
|
||||
});
|
||||
expect(observed.malformed).toEqual([
|
||||
{ line: 2, reason: "member-line" },
|
||||
{ line: 3, reason: "member-line" },
|
||||
{ line: 4, reason: "class-line" },
|
||||
{ line: 5, reason: "member-without-class" },
|
||||
]);
|
||||
});
|
||||
|
||||
it.each([
|
||||
["empty", ""],
|
||||
["comment-only", "# compiler: R8\n# just a comment\n"],
|
||||
|
||||
@@ -116,11 +116,26 @@ export type ProguardResolution<Mapped, Verifier extends string> =
|
||||
|
||||
const HEADER =
|
||||
/^#\s*(compiler|compiler_version|min_api|pg_map_id|pg_map_hash):\s*(.*)$/u;
|
||||
const CLASS_LINE = /^([^\s:()]+) -> ([^\s:()]+):$/u;
|
||||
const FIELD_LINE = /^\s+([^\s:()]+) ([^\s:()]+) -> ([^\s:()]+)$/u;
|
||||
const METHOD_LINE =
|
||||
/^\s+(?:(\d+):(?:(\d+):)?)?([^\s:()]+) ([^\s:()]+)\(([^()]*)\)(?::(\d+)(?::(\d+))?)? -> ([^\s:()]+)$/u;
|
||||
const MAPPING_NAME = /^[^\s:()]+$/u;
|
||||
const FIELD_DECLARATION = /^\s+([^\s:()]+)[ \t]+([^\s:()]+)$/u;
|
||||
const METHOD_DECLARATION =
|
||||
/^\s+(?:(\d+):(?:(\d+):)?)?([^\s:()]+)[ \t]+([^\s:()]+)\(([^()]*)\)(?::(\d+)(?::(\d+))?)?$/u;
|
||||
const TYPE_TOKEN = /^[^\s(),;<>:[\]]+(?:\[\])*$/u;
|
||||
|
||||
interface MappingDeclaration {
|
||||
readonly original: string;
|
||||
readonly residual: string;
|
||||
}
|
||||
|
||||
/** A single arrow separates both forms of declaration, with optional spacing. */
|
||||
const splitDeclaration = (line: string): MappingDeclaration | undefined => {
|
||||
const arrow = line.indexOf("->");
|
||||
if (arrow < 0 || line.indexOf("->", arrow + 2) >= 0) return undefined;
|
||||
return {
|
||||
original: line.slice(0, arrow).trimEnd(),
|
||||
residual: line.slice(arrow + 2).trimStart(),
|
||||
};
|
||||
};
|
||||
const DEX_PRIMITIVES = new Map([
|
||||
["boolean", "Z"],
|
||||
["byte", "B"],
|
||||
@@ -392,13 +407,20 @@ const parseClassLine = (state: ParseState, line: string, number: number) => {
|
||||
closeGroup(state);
|
||||
if (state.failure !== undefined) return;
|
||||
state.last = undefined;
|
||||
const match = CLASS_LINE.exec(line);
|
||||
if (match === null) {
|
||||
const declaration = splitDeclaration(line);
|
||||
const residual = declaration?.residual.endsWith(":")
|
||||
? declaration.residual.slice(0, -1)
|
||||
: "";
|
||||
if (
|
||||
declaration === undefined ||
|
||||
!MAPPING_NAME.test(declaration.original) ||
|
||||
!MAPPING_NAME.test(residual)
|
||||
) {
|
||||
state.current = null;
|
||||
malformed(state, number, "class-line");
|
||||
return;
|
||||
}
|
||||
const [, original = "", residual = ""] = match;
|
||||
const { original } = declaration;
|
||||
if (
|
||||
!chargeIndex(
|
||||
state,
|
||||
@@ -425,10 +447,14 @@ const parseClassLine = (state: ParseState, line: string, number: number) => {
|
||||
state.residualAliases.set(record.name, null);
|
||||
};
|
||||
|
||||
const parseField = (state: ParseState, record: ClassRecord, line: string) => {
|
||||
const match = FIELD_LINE.exec(line);
|
||||
const parseField = (
|
||||
state: ParseState,
|
||||
record: ClassRecord,
|
||||
{ original, residual: obfuscated }: MappingDeclaration,
|
||||
) => {
|
||||
const match = FIELD_DECLARATION.exec(original);
|
||||
if (match === null) return false;
|
||||
const [, type = "", name = "", obfuscated = ""] = match;
|
||||
const [, type = "", name = ""] = match;
|
||||
if (!validType(type, false)) return false;
|
||||
closeGroup(state);
|
||||
if (state.failure !== undefined) return true;
|
||||
@@ -458,8 +484,12 @@ const methodRange = (start?: string, end?: string): string | null | false => {
|
||||
return Number(start) > Number(last) ? false : `${start}:${last}`;
|
||||
};
|
||||
|
||||
const parseMethod = (state: ParseState, record: ClassRecord, line: string) => {
|
||||
const match = METHOD_LINE.exec(line);
|
||||
const parseMethod = (
|
||||
state: ParseState,
|
||||
record: ClassRecord,
|
||||
{ original, residual: obfuscated }: MappingDeclaration,
|
||||
) => {
|
||||
const match = METHOD_DECLARATION.exec(original);
|
||||
if (match === null) return false;
|
||||
const [
|
||||
,
|
||||
@@ -470,7 +500,6 @@ const parseMethod = (state: ParseState, record: ClassRecord, line: string) => {
|
||||
args = "",
|
||||
originalStart,
|
||||
originalEnd,
|
||||
obfuscated = "",
|
||||
] = match;
|
||||
// Count before split: a small source string can otherwise allocate millions
|
||||
// of parameter slots before the retained-representation admission runs.
|
||||
@@ -543,7 +572,13 @@ const parseMember = (state: ParseState, line: string, number: number) => {
|
||||
malformed(state, number, "member-without-class");
|
||||
return;
|
||||
}
|
||||
if (parseField(state, record, line) || parseMethod(state, record, line))
|
||||
const declaration = splitDeclaration(line);
|
||||
if (
|
||||
declaration !== undefined &&
|
||||
MAPPING_NAME.test(declaration.residual) &&
|
||||
(parseField(state, record, declaration) ||
|
||||
parseMethod(state, record, declaration))
|
||||
)
|
||||
return;
|
||||
if (state.failure !== undefined) return;
|
||||
closeGroup(state);
|
||||
|
||||
Reference in new issue
Block a user