File tree Expand file tree Collapse file tree 1 file changed +10
-3
lines changed
src/main/kotlin/app/revanced/patcher/util Expand file tree Collapse file tree 1 file changed +10
-3
lines changed Original file line number Diff line number Diff line change @@ -4,7 +4,9 @@ import org.w3c.dom.Document
4
4
import java.io.Closeable
5
5
import java.io.File
6
6
import java.io.InputStream
7
+ import java.io.StringWriter
7
8
import javax.xml.parsers.DocumentBuilderFactory
9
+ import javax.xml.transform.OutputKeys
8
10
import javax.xml.transform.TransformerFactory
9
11
import javax.xml.transform.dom.DOMSource
10
12
import javax.xml.transform.stream.StreamResult
@@ -35,14 +37,19 @@ class Document internal constructor(
35
37
}
36
38
37
39
it.outputStream().buffered().use { stream ->
38
- TransformerFactory .newInstance()
39
- .newTransformer()
40
- .transform(DOMSource (this ), StreamResult (stream))
40
+ val transformer = TransformerFactory .newInstance().newTransformer()
41
+ // Set to UTF-16 but encode as UTF-8 to prevent surrogate pairs from being escaped to broken numeric character references.
42
+ if (isAndroid) {
43
+ transformer.setOutputProperty(OutputKeys .ENCODING , " UTF-16" )
44
+ transformer.setOutputProperty(OutputKeys .OMIT_XML_DECLARATION , " yes" )
45
+ }
46
+ transformer.transform(DOMSource (this ), StreamResult (stream))
41
47
}
42
48
}
43
49
}
44
50
45
51
private companion object {
46
52
private val readerCount = mutableMapOf<File , Int >()
53
+ private val isAndroid = System .getProperty(" java.runtime.name" ).equals(" Android Runtime" )
47
54
}
48
55
}
You can’t perform that action at this time.
0 commit comments