Skip to content

Commit 6bb30fc

Browse files
romtsnclaude
andcommitted
fix(r8): Normalize inverted line ranges in mapping parser
Inverted minified ranges (e.g. `5:3:void main() -> main`) and inverted original ranges (e.g. `2:5:void main():5:2 -> main`) are now normalized by swapping the start/end values. This fixes incorrect line interpolation for these edge cases. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent ca666d2 commit 6bb30fc

File tree

1 file changed

+18
-2
lines changed

1 file changed

+18
-2
lines changed

src/builder.rs

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -292,11 +292,11 @@ impl<'s> ParsedProguardMapping<'s> {
292292
None
293293
};
294294
// in case the mapping has no line records, we use `0` here.
295-
let (startline, endline) =
295+
let (mut startline, mut endline) =
296296
line_mapping.as_ref().map_or((0, 0), |line_mapping| {
297297
(line_mapping.startline, line_mapping.endline)
298298
});
299-
let (original_startline, original_endline) =
299+
let (mut original_startline, mut original_endline) =
300300
line_mapping.map_or((0, None), |line_mapping| {
301301
match line_mapping.original_startline {
302302
Some(original_startline) => {
@@ -306,6 +306,22 @@ impl<'s> ParsedProguardMapping<'s> {
306306
}
307307
});
308308

309+
// Normalize inverted ranges: if minified range is inverted,
310+
// swap both minified and original pairs.
311+
if startline > endline {
312+
std::mem::swap(&mut startline, &mut endline);
313+
if let Some(ref mut oe) = original_endline {
314+
std::mem::swap(&mut original_startline, oe);
315+
}
316+
}
317+
// If original range is still inverted, swap it independently.
318+
if let Some(oe) = original_endline {
319+
if original_startline > oe {
320+
original_endline = Some(original_startline);
321+
original_startline = oe;
322+
}
323+
}
324+
309325
let Some((current_class_obfuscated, current_class_original)) =
310326
current_class_name
311327
else {

0 commit comments

Comments
 (0)