From fcbbfa1930671409765dad184673e162c538ca79 Mon Sep 17 00:00:00 2001 From: JrMasterModelBuilder Date: Sat, 4 May 2024 00:10:53 -0400 Subject: [PATCH] Proper decoding --- util/flashcn.mjs | 3 ++- util/harman.mjs | 22 +++++++++------------- 2 files changed, 11 insertions(+), 14 deletions(-) diff --git a/util/flashcn.mjs b/util/flashcn.mjs index 8b1075d6..2e2d43fa 100644 --- a/util/flashcn.mjs +++ b/util/flashcn.mjs @@ -187,7 +187,8 @@ async function listDebug() { } const html = await htmlRes.text(); - const dom = new DOMParser().parseFromString(html, 'text/html'); + const domParser = new DOMParser({errorHandler: {}}); + const dom = domParser.parseFromString(html, 'text/html'); const hrefs = list(dom.getElementsByTagName('a')) .map(a => new URL(a.getAttribute('href') || '', htmlUrl)) .filter(u => u.pathname.startsWith('/cdm/')); diff --git a/util/harman.mjs b/util/harman.mjs index aafb0bf9..fa9fc1ed 100644 --- a/util/harman.mjs +++ b/util/harman.mjs @@ -1,4 +1,6 @@ -import {retry} from './util.mjs'; +import {DOMParser} from '@xmldom/xmldom'; + +import {list, retry} from './util.mjs'; // The API this page loads download list from. // https://airsdk.harman.com/download @@ -35,15 +37,6 @@ export function cookies(list) { return list.map(c => c.split(';')[0]).join('; '); } -function attrs(tag) { - const reg = /\s([a-z0-9-]+)(=("([^"]*)"|'([^']*)'|(\S*)))?/gi; - const attrs = {}; - for (let m; (m = reg.exec(tag)); ) { - attrs[m[1]] = m[4] ?? m[5] ?? m[6] ?? null; - } - return attrs; -} - export async function sdks() { const response = await retry(() => fetch(apiUrl, { @@ -127,14 +120,17 @@ export async function runtimes() { } const html = await response.text(); - const scripts = html.match(/]*>/gi); - if (!scripts) { + const domParser = new DOMParser({errorHandler: {}}); + const dom = domParser.parseFromString(html, 'text/html'); + const scripts = list(dom.getElementsByTagName('script')); + if (!scripts.length) { throw new Error(`No script tags: ${runtimeUrl}`); } let version = ''; let hashes = null; - for (const {src} of [...scripts].map(attrs).reverse()) { + for (const script of [...scripts].reverse()) { + const src = script.getAttribute('src'); if (!src) { continue; }