Skip to content

Commit

Permalink
feat: de-dupe attribute names during styles writing (#3404)
Browse files Browse the repository at this point in the history
  • Loading branch information
iBotPeaches committed Oct 16, 2023
1 parent 03fa70b commit 247735c
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
import org.xmlpull.v1.XmlSerializer;

import java.io.IOException;
import java.util.HashSet;
import java.util.Set;
import java.util.logging.Logger;

public class ResStyleValue extends ResBagValue implements ResValuesXmlSerializable {
Expand All @@ -47,6 +49,8 @@ public void serializeToResValuesXml(XmlSerializer serializer,
} else if (res.getResSpec().getName().indexOf('.') != -1) {
serializer.attribute(null, "parent", "");
}

Set<String> processedNames = new HashSet<>();
for (Duo<ResReferenceValue, ResScalarValue> mItem : mItems) {
ResResSpec spec = mItem.m1.getReferent();

Expand All @@ -70,6 +74,11 @@ public void serializeToResValuesXml(XmlSerializer serializer,
name = "@" + spec.getFullName(res.getResSpec().getPackage(), false);
}

// #3400 - Skip duplicate values, commonly seen are duplicate key-pairs on styles.
if (!isAnalysisMode() && processedNames.contains(name)) {
continue;
}

if (value == null) {
value = mItem.m2.encodeAsResXmlValue();
}
Expand All @@ -82,8 +91,11 @@ public void serializeToResValuesXml(XmlSerializer serializer,
serializer.attribute(null, "name", name);
serializer.text(value);
serializer.endTag(null, "item");

processedNames.add(name);
}
serializer.endTag(null, "style");
processedNames.clear();
}

private final Duo<ResReferenceValue, ResScalarValue>[] mItems;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,8 @@ public class ResValue {
public boolean shouldRemoveUnknownRes() {
return Config.getInstance().isDecodeResolveModeRemoving();
}

public boolean isAnalysisMode() {
return Config.getInstance().analysisMode;
}
}

0 comments on commit 247735c

Please sign in to comment.