fix(res): add missing namespace declarations (PR #2102)
* fix(res): add missing namespace declarations * remove `writer.getIndent() == 0` --------- Co-authored-by: skylot <118523+skylot@users.noreply.github.com>
This commit is contained in:
@@ -40,6 +40,7 @@ public class BinaryXMLParser extends CommonBinaryParser {
|
||||
private final Map<Integer, String> resNames;
|
||||
private Map<String, String> nsMap;
|
||||
private Set<String> nsMapGenerated;
|
||||
private Set<String> definedNamespaces;
|
||||
private final Map<String, String> tagAttrDeobfNames = new HashMap<>();
|
||||
|
||||
private ICodeWriter writer;
|
||||
@@ -78,11 +79,13 @@ public class BinaryXMLParser extends CommonBinaryParser {
|
||||
}
|
||||
nsMapGenerated = new HashSet<>();
|
||||
nsMap = new HashMap<>();
|
||||
definedNamespaces = new HashSet<>();
|
||||
writer = rootNode.makeCodeWriter();
|
||||
writer.add("<?xml version=\"1.0\" encoding=\"utf-8\"?>");
|
||||
firstElement = true;
|
||||
decode();
|
||||
nsMap = null;
|
||||
definedNamespaces = null;
|
||||
ICodeInfo codeInfo = writer.finish();
|
||||
this.classNameCache = null; // reset class name cache
|
||||
return codeInfo;
|
||||
@@ -269,15 +272,18 @@ public class BinaryXMLParser extends CommonBinaryParser {
|
||||
int idIndex = is.readInt16();
|
||||
int classIndex = is.readInt16();
|
||||
int styleIndex = is.readInt16();
|
||||
if ("manifest".equals(currentTag) || writer.getIndent() == 0) {
|
||||
if ("manifest".equals(currentTag) || definedNamespaces.size() != nsMap.size()) {
|
||||
for (Map.Entry<String, String> entry : nsMap.entrySet()) {
|
||||
String nsValue = getValidTagAttributeName(entry.getValue());
|
||||
writer.add(" xmlns");
|
||||
if (nsValue != null && !nsValue.trim().isEmpty()) {
|
||||
writer.add(':');
|
||||
writer.add(nsValue);
|
||||
if (!definedNamespaces.contains(entry.getKey())) {
|
||||
definedNamespaces.add(entry.getKey());
|
||||
String nsValue = getValidTagAttributeName(entry.getValue());
|
||||
writer.add(" xmlns");
|
||||
if (nsValue != null && !nsValue.trim().isEmpty()) {
|
||||
writer.add(':');
|
||||
writer.add(nsValue);
|
||||
}
|
||||
writer.add("=\"").add(StringUtils.escapeXML(entry.getKey())).add('"');
|
||||
}
|
||||
writer.add("=\"").add(StringUtils.escapeXML(entry.getKey())).add('"');
|
||||
}
|
||||
}
|
||||
boolean attrNewLine = attributeCount != 1 && this.attrNewLine;
|
||||
|
||||
Reference in New Issue
Block a user