mirror of
https://github.com/revanced/ARSCLib.git
synced 2025-04-29 22:04:25 +02:00
quote empty whitespaces for xml encoding
This commit is contained in:
parent
b07b8bddfb
commit
f49799a02d
@ -29,7 +29,10 @@ public class XMLDecodeHelper {
|
||||
return;
|
||||
}
|
||||
if(!stringItem.hasStyle()){
|
||||
writer.text(ValueDecoder.escapeSpecialCharacter(stringItem.get()));
|
||||
String text = stringItem.get();
|
||||
text = ValueDecoder.escapeSpecialCharacter(text);
|
||||
text = ValueDecoder.quoteWhitespace(text);
|
||||
writer.text(text);
|
||||
}else {
|
||||
String xml = stringItem.getXml();
|
||||
XMLElement element = parseSpanSafe(xml);
|
||||
|
@ -1,4 +1,4 @@
|
||||
/*
|
||||
/*
|
||||
* Copyright (C) 2022 github.com/REAndroid
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
@ -158,7 +158,9 @@ import java.util.*;
|
||||
addStyleElement(element);
|
||||
}else {
|
||||
String text = ValueDecoder
|
||||
.unEscapeSpecialCharacter(element.getTextContent());
|
||||
.unQuoteWhitespace(element.getTextContent());
|
||||
text = ValueDecoder
|
||||
.unEscapeSpecialCharacter(text);
|
||||
addString(text);
|
||||
}
|
||||
}
|
||||
|
@ -25,7 +25,6 @@ class XMLValuesEncoderString extends XMLValuesEncoder{
|
||||
super(materials);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
void encodeValue(Entry entry, XMLElement element){
|
||||
if(!element.hasChildElements()){
|
||||
@ -36,7 +35,9 @@ class XMLValuesEncoderString extends XMLValuesEncoder{
|
||||
}
|
||||
@Override
|
||||
void encodeStringValue(Entry entry, String value){
|
||||
entry.setValueAsString(ValueDecoder.unEscapeSpecialCharacter(value));
|
||||
value = ValueDecoder.unQuoteWhitespace(value);
|
||||
value = ValueDecoder.unEscapeSpecialCharacter(value);
|
||||
entry.setValueAsString(value);
|
||||
}
|
||||
@Override
|
||||
void encodeNullValue(Entry entry){
|
||||
|
@ -50,6 +50,48 @@ public class ValueDecoder {
|
||||
}
|
||||
return text.substring(1);
|
||||
}
|
||||
public static String quoteWhitespace(String text){
|
||||
if(!isWhiteSpace(text)){
|
||||
return text;
|
||||
}
|
||||
return "\"" + text + "\"";
|
||||
}
|
||||
public static String unQuoteWhitespace(String text){
|
||||
if(text == null || text.length() < 3){
|
||||
return text;
|
||||
}
|
||||
if(text.charAt(0) != '"' || text.charAt(text.length()-1) != '"'){
|
||||
return text;
|
||||
}
|
||||
String unQuoted = text.substring(1, text.length()-1);
|
||||
if(!isWhiteSpace(unQuoted)){
|
||||
return text;
|
||||
}
|
||||
return unQuoted;
|
||||
}
|
||||
private static boolean isWhiteSpace(String text){
|
||||
if(text == null || text.length() == 0){
|
||||
return false;
|
||||
}
|
||||
char[] chars = text.toCharArray();
|
||||
for(int i = 0; i < chars.length; i++){
|
||||
if(!isWhiteSpace(chars[i])){
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
private static boolean isWhiteSpace(char ch){
|
||||
switch (ch){
|
||||
case ' ':
|
||||
case '\n':
|
||||
case '\r':
|
||||
case '\t':
|
||||
return true;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
private static boolean isSpecialCharacter(char ch){
|
||||
switch (ch){
|
||||
case '@':
|
||||
|
Loading…
x
Reference in New Issue
Block a user