mirror of
https://github.com/revanced/ARSCLib.git
synced 2025-04-30 06:14: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;
|
return;
|
||||||
}
|
}
|
||||||
if(!stringItem.hasStyle()){
|
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 {
|
}else {
|
||||||
String xml = stringItem.getXml();
|
String xml = stringItem.getXml();
|
||||||
XMLElement element = parseSpanSafe(xml);
|
XMLElement element = parseSpanSafe(xml);
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (C) 2022 github.com/REAndroid
|
* Copyright (C) 2022 github.com/REAndroid
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
@ -158,7 +158,9 @@ import java.util.*;
|
|||||||
addStyleElement(element);
|
addStyleElement(element);
|
||||||
}else {
|
}else {
|
||||||
String text = ValueDecoder
|
String text = ValueDecoder
|
||||||
.unEscapeSpecialCharacter(element.getTextContent());
|
.unQuoteWhitespace(element.getTextContent());
|
||||||
|
text = ValueDecoder
|
||||||
|
.unEscapeSpecialCharacter(text);
|
||||||
addString(text);
|
addString(text);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -25,7 +25,6 @@ class XMLValuesEncoderString extends XMLValuesEncoder{
|
|||||||
super(materials);
|
super(materials);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
void encodeValue(Entry entry, XMLElement element){
|
void encodeValue(Entry entry, XMLElement element){
|
||||||
if(!element.hasChildElements()){
|
if(!element.hasChildElements()){
|
||||||
@ -36,7 +35,9 @@ class XMLValuesEncoderString extends XMLValuesEncoder{
|
|||||||
}
|
}
|
||||||
@Override
|
@Override
|
||||||
void encodeStringValue(Entry entry, String value){
|
void encodeStringValue(Entry entry, String value){
|
||||||
entry.setValueAsString(ValueDecoder.unEscapeSpecialCharacter(value));
|
value = ValueDecoder.unQuoteWhitespace(value);
|
||||||
|
value = ValueDecoder.unEscapeSpecialCharacter(value);
|
||||||
|
entry.setValueAsString(value);
|
||||||
}
|
}
|
||||||
@Override
|
@Override
|
||||||
void encodeNullValue(Entry entry){
|
void encodeNullValue(Entry entry){
|
||||||
|
@ -50,6 +50,48 @@ public class ValueDecoder {
|
|||||||
}
|
}
|
||||||
return text.substring(1);
|
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){
|
private static boolean isSpecialCharacter(char ch){
|
||||||
switch (ch){
|
switch (ch){
|
||||||
case '@':
|
case '@':
|
||||||
|
Loading…
x
Reference in New Issue
Block a user