mirror of
https://github.com/morluto/rea.git
synced 2026-11-30 18:39:24 +00:00
* fix(android): share decoded manifest root and package admission Refs #12139 * fix(apktool): keep foreign XML out of decoded string entries Refs #12139
28 lines
902 B
TypeScript
28 lines
902 B
TypeScript
import type { Element } from "@xmldom/xmldom";
|
|
|
|
import { err, ok, type Result } from "../result.js";
|
|
import {
|
|
isUnqualifiedXmlElement,
|
|
parseXmlDocument,
|
|
type XmlParseFailure,
|
|
} from "../xmlDocument.js";
|
|
|
|
/** Read the decoded root and its package without validating package-name syntax. */
|
|
export const parseDecodedAndroidManifest = (
|
|
source: string,
|
|
doctype: "allow" | "reject",
|
|
): Result<
|
|
{ readonly root: Element; readonly packageName: string | null },
|
|
XmlParseFailure | { readonly kind: "unexpected-root" }
|
|
> => {
|
|
const parsed = parseXmlDocument(source, { doctype, lineEndings: "preserve" });
|
|
if (!parsed.ok) return parsed;
|
|
const root = parsed.value.documentElement;
|
|
if (!isUnqualifiedXmlElement(root) || root.localName !== "manifest")
|
|
return err({ kind: "unexpected-root" });
|
|
return ok({
|
|
root,
|
|
packageName: root.getAttributeNS(null, "package") || null,
|
|
});
|
|
};
|