Fix url encoding (#679)

This commit is contained in:
Koen Kanters
2025-02-07 20:55:13 +01:00
committed by GitHub
parent ebe2aa59d0
commit 50db043486
5 changed files with 39 additions and 34 deletions
+1 -1
View File
@@ -78,7 +78,7 @@ export function getOutDir(folderName: string, basePath: string = BASE_IMAGES_DIR
}
export function getRepoFirmwareFileUrl(folderName: string, fileName: string, basePath: string = BASE_IMAGES_DIR): string {
return BASE_REPO_URL + path.posix.join(REPO_BRANCH, basePath, folderName, fileName);
return BASE_REPO_URL + path.posix.join(REPO_BRANCH, basePath, folderName, encodeURIComponent(fileName));
}
export function writeManifest(fileName: string, firmwareList: RepoImageMeta[]): void {
+13 -8
View File
@@ -101,8 +101,7 @@ async function download3rdParties(
continue;
}
// reverse add.js logic
const fileName = unescape(meta.url.split('/').pop()!);
const fileName = decodeURIComponent(meta.url.split('/').pop()!);
const outDirName = outDirFinder(meta);
if (outDirName) {
@@ -245,13 +244,9 @@ function checkImagesAgainstManifests(github: Octokit, core: typeof CoreApi, cont
for (const fileName of readdirSync(subfolderPath)) {
const firmwareFilePath = path.join(subfolderPath, fileName);
const fileRelUrl = path.posix.join(imagesDir, subfolderName, fileName);
// previous add.js used escape() for url property
const escFileRelUrl = escape(fileRelUrl);
const fileRelUrl = path.posix.join(imagesDir, subfolderName, encodeURIComponent(fileName));
// take local images only
const inManifest = manifest.filter(
(m) => m.url.startsWith(BASE_REPO_URL + REPO_BRANCH) && (m.url.endsWith(fileRelUrl) || m.url.endsWith(escFileRelUrl)),
);
const inManifest = manifest.filter((m) => m.url.startsWith(BASE_REPO_URL + REPO_BRANCH) && m.url.endsWith(fileRelUrl));
if (inManifest.length === 0) {
core.warning(`Not found in base manifest: ${firmwareFilePath}.`);
@@ -396,3 +391,13 @@ export async function reProcessAllImages(
checkImagesAgainstManifests(github, core, context, removeNotInManifest);
}
// To run locally uncomment below and run with `npx tsx src/ghw_reprocess_all_images.ts`
// const core = {
// info: (msg) => console.log(msg),
// warning: (msg) => console.log(msg),
// error: (msg) => console.error(msg),
// startGroup: () => {},
// endGroup: () => {},
// }
// checkImagesAgainstManifests(null, core, null, false);