Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix url encoding #679

Merged
merged 3 commits into from
Feb 7, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 21 additions & 21 deletions index.json
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@
"fileName": "ED - HA - VOC Sensor-SSIG 4.0.1.zigbee",
"fileVersion": 262145,
"fileSize": 194471,
"url": "https://github.com/Koenkk/zigbee-OTA/raw/master/images/Develco/ED - HA - VOC Sensor-SSIG 4.0.1.zigbee",
"url": "https://github.com/Koenkk/zigbee-OTA/raw/master/images/Develco/ED%20-%20HA%20-%20VOC%20Sensor-SSIG%204.0.1.zigbee",
"imageType": 800,
"manufacturerCode": 4117,
"sha512": "d6779d7e0879c86d8a7479f352d187cb854cc8586b57245dc96f6c202ccf455a19acb5d360b9ae62510e5b7ae2ea67a95841ff822a5a3a69199d5841dbcf2dbe",
Expand Down Expand Up @@ -420,7 +420,7 @@
"fileName": "ZB21S3_HZC_Dimmer1_EcoDim-Zigbee 3.0_1.01_20230908.ota",
"fileVersion": 4,
"fileSize": 286646,
"url": "https://github.com/Koenkk/zigbee-OTA/raw/master/images/EcoDim/ZB21S3_HZC_Dimmer1_EcoDim-Zigbee 3.0_1.01_20230908.ota",
"url": "https://github.com/Koenkk/zigbee-OTA/raw/master/images/EcoDim/ZB21S3_HZC_Dimmer1_EcoDim-Zigbee%203.0_1.01_20230908.ota",
"imageType": 1000,
"manufacturerCode": 4714,
"sha512": "9b7835e32ef5af35385710332838099c5dce99a398ae04a1a769d67935fb0752ca4da58892f13bc842cbf8f9ae20516142fe9b66eff3e8ebef6577a71a1d9b0b",
Expand All @@ -442,7 +442,7 @@
"fileName": "GL-B-007P_V17_OTAV7_20210305_100%.ota",
"fileVersion": 7,
"fileSize": 291702,
"url": "https://github.com/Koenkk/zigbee-OTA/raw/master/images/Gledopto/GL-B-007P_V17_OTAV7_20210305_100%.ota",
"url": "https://github.com/Koenkk/zigbee-OTA/raw/master/images/Gledopto/GL-B-007P_V17_OTAV7_20210305_100%25.ota",
"imageType": 0,
"manufacturerCode": 4687,
"sha512": "8c3431b4d60d31e3ac16468601b64b3f8da0c2cf122c638a654b71543de901bfaf2e3afe5a0a8084d20d32478ad61738c86f33a2548211ea8f2367900fb1b620",
Expand Down Expand Up @@ -496,7 +496,7 @@
"fileName": "GL-D-005P_V11076801_OTAV12_20211108_60%.ota",
"fileVersion": 18,
"fileSize": 291826,
"url": "https://github.com/Koenkk/zigbee-OTA/raw/master/images/Gledopto/GL-D-005P_V11076801_OTAV12_20211108_60%.ota",
"url": "https://github.com/Koenkk/zigbee-OTA/raw/master/images/Gledopto/GL-D-005P_V11076801_OTAV12_20211108_60%25.ota",
"imageType": 0,
"manufacturerCode": 4687,
"sha512": "966bbc8a44693eb5a91c4cf64bf59b91d291335d223cec1ffc65a6d7b3fe339be4e70b90908aea0bc0a6f7ea4ff130898b4492e0818d7f05220582097a543f9d",
Expand Down Expand Up @@ -537,7 +537,7 @@
"fileName": "GL-FL-005P_V14_OTAV4_20210119_100%.ota",
"fileVersion": 4,
"fileSize": 291546,
"url": "https://github.com/Koenkk/zigbee-OTA/raw/master/images/Gledopto/GL-FL-005P_V14_OTAV4_20210119_100%.ota",
"url": "https://github.com/Koenkk/zigbee-OTA/raw/master/images/Gledopto/GL-FL-005P_V14_OTAV4_20210119_100%25.ota",
"imageType": 0,
"manufacturerCode": 4687,
"sha512": "35815df1ef7ec3f492076f118c77bf21a846ea68c07766f574eeb67d34cb00cee8e374edabfba47c1b66763c222c1ce2133a06cae8bece483b0be9d90f54a2b8",
Expand All @@ -548,7 +548,7 @@
"fileName": "GL-FL-006P_V14_OTAV4_20210119_100%.ota",
"fileVersion": 4,
"fileSize": 291546,
"url": "https://github.com/Koenkk/zigbee-OTA/raw/master/images/Gledopto/GL-FL-006P_V14_OTAV4_20210119_100%.ota",
"url": "https://github.com/Koenkk/zigbee-OTA/raw/master/images/Gledopto/GL-FL-006P_V14_OTAV4_20210119_100%25.ota",
"imageType": 0,
"manufacturerCode": 4687,
"sha512": "fec3c2e153d30a3a01193b0b7a96e3ef2e6613d1de58e5ee01d6d66baf7d2d4e8c1bd94b3aece0effc94145e8b5b783f192ff752a9ae640044b895faabbbcd63",
Expand Down Expand Up @@ -580,7 +580,7 @@
"fileName": "GL-S-007P_V15_A1_OTAV5_20210201_90%.ota",
"fileVersion": 5,
"fileSize": 291622,
"url": "https://github.com/Koenkk/zigbee-OTA/raw/master/images/Gledopto/GL-S-007P_V15_A1_OTAV5_20210201_90%.ota",
"url": "https://github.com/Koenkk/zigbee-OTA/raw/master/images/Gledopto/GL-S-007P_V15_A1_OTAV5_20210201_90%25.ota",
"imageType": 0,
"manufacturerCode": 4687,
"sha512": "ce512a11f0d4e603edd3a93686cf5d666ee447bee1d24a6e06ce544e2ebf941a4a4e3fcc737cdf8c65821f8e008366b269d9a221fb55cfa54065380442c5f432",
Expand Down Expand Up @@ -1901,7 +1901,7 @@
"fileName": "1166-0128-24031511-upgradeMe-RS 226.zigbee",
"fileVersion": 604181777,
"fileSize": 262013,
"url": "https://github.com/Koenkk/zigbee-OTA/raw/master/images/Innr/1166-0128-24031511-upgradeMe-RS 226.zigbee",
"url": "https://github.com/Koenkk/zigbee-OTA/raw/master/images/Innr/1166-0128-24031511-upgradeMe-RS%20226.zigbee",
"imageType": 296,
"manufacturerCode": 4454,
"sha512": "8d239c44c73d403c15448d5c7e4c15d1b25463bbb4681fdfd184cdb6e5f72b4797d71b746097b14ce0e09b631a9e6a4b4d103caa1175ccd257b9193fe7261120",
Expand All @@ -1911,7 +1911,7 @@
"fileName": "1166-0129-24031511-upgradeMe-RS 227 T.zigbee",
"fileVersion": 604181777,
"fileSize": 268720,
"url": "https://github.com/Koenkk/zigbee-OTA/raw/master/images/Innr/1166-0129-24031511-upgradeMe-RS 227 T.zigbee",
"url": "https://github.com/Koenkk/zigbee-OTA/raw/master/images/Innr/1166-0129-24031511-upgradeMe-RS%20227%20T.zigbee",
"imageType": 297,
"manufacturerCode": 4454,
"sha512": "c7365c9576886a4fc4ddb6e1256d7dcb75f788ec92631e5cb13b8ae317b876954988632010fbe6604a5d1fd5f25936f61387dd6dda20ca61eb5848999278b964",
Expand All @@ -1921,7 +1921,7 @@
"fileName": "1166-012A-24031511-upgradeMe-RB 245.zigbee",
"fileVersion": 604181777,
"fileSize": 262013,
"url": "https://github.com/Koenkk/zigbee-OTA/raw/master/images/Innr/1166-012A-24031511-upgradeMe-RB 245.zigbee",
"url": "https://github.com/Koenkk/zigbee-OTA/raw/master/images/Innr/1166-012A-24031511-upgradeMe-RB%20245.zigbee",
"imageType": 298,
"manufacturerCode": 4454,
"sha512": "a6606afeb0ce56b20d7aa839d40ec079851fa6b39a80a65707d4dbd900fb2ac2582db40b5dc519c473fc51d1e630bb81aded66545283b77f2ac5e91699771cac",
Expand All @@ -1931,7 +1931,7 @@
"fileName": "1166-012B-24031511-upgradeMe-RB 249 T.zigbee",
"fileVersion": 604181777,
"fileSize": 268720,
"url": "https://github.com/Koenkk/zigbee-OTA/raw/master/images/Innr/1166-012B-24031511-upgradeMe-RB 249 T.zigbee",
"url": "https://github.com/Koenkk/zigbee-OTA/raw/master/images/Innr/1166-012B-24031511-upgradeMe-RB%20249%20T.zigbee",
"imageType": 299,
"manufacturerCode": 4454,
"sha512": "d3c86737e3a9de6102c013b00b69ea37c551debb898c25f5ce67bfdab4c52b8acca5932e34953d06087dd078d77d83d5d8654c695af6a18440fc2acea0c07f5f",
Expand All @@ -1941,7 +1941,7 @@
"fileName": "1166-012C-24031511-upgradeMe-RB 251 C.zigbee",
"fileVersion": 604181777,
"fileSize": 318314,
"url": "https://github.com/Koenkk/zigbee-OTA/raw/master/images/Innr/1166-012C-24031511-upgradeMe-RB 251 C.zigbee",
"url": "https://github.com/Koenkk/zigbee-OTA/raw/master/images/Innr/1166-012C-24031511-upgradeMe-RB%20251%20C.zigbee",
"imageType": 300,
"manufacturerCode": 4454,
"sha512": "7be7ca7b54e3f404f164f0ae22386e6180f30a72334909648240a45490002b291e4031a6604d3ed7b894a1105a49f6d088df4a085f434a8b1be512a8552a995d",
Expand All @@ -1951,7 +1951,7 @@
"fileName": "1166-012D-24031511-upgradeMe-RB 266.zigbee",
"fileVersion": 604181777,
"fileSize": 262013,
"url": "https://github.com/Koenkk/zigbee-OTA/raw/master/images/Innr/1166-012D-24031511-upgradeMe-RB 266.zigbee",
"url": "https://github.com/Koenkk/zigbee-OTA/raw/master/images/Innr/1166-012D-24031511-upgradeMe-RB%20266.zigbee",
"imageType": 301,
"manufacturerCode": 4454,
"sha512": "317a109be00c0f7b96e7bdb1d60eab57d68149e3a9da78b7fe21db165d22165fef389b8eb4c0463abe27d5e9680a48975a72687900f5baa5e2df5db16eda1348",
Expand All @@ -1961,7 +1961,7 @@
"fileName": "1166-012E-24031511-upgradeMe-RB 279 T.zigbee",
"fileVersion": 604181777,
"fileSize": 268720,
"url": "https://github.com/Koenkk/zigbee-OTA/raw/master/images/Innr/1166-012E-24031511-upgradeMe-RB 279 T.zigbee",
"url": "https://github.com/Koenkk/zigbee-OTA/raw/master/images/Innr/1166-012E-24031511-upgradeMe-RB%20279%20T.zigbee",
"imageType": 302,
"manufacturerCode": 4454,
"sha512": "96c85aab44c85dfaecf0e5728b87de5920aa6d1030e18831cbfd737b5e0772937f55f0e7da1c5356ef6e6756f7c4cffbfc7d0ba095e63d053bde2535a450b72d",
Expand All @@ -1971,7 +1971,7 @@
"fileName": "1166-012F-24021511-upgradeMe -RB 286 C.zigbee",
"fileVersion": 604116241,
"fileSize": 302698,
"url": "https://github.com/Koenkk/zigbee-OTA/raw/master/images/Innr/1166-012F-24021511-upgradeMe -RB 286 C.zigbee",
"url": "https://github.com/Koenkk/zigbee-OTA/raw/master/images/Innr/1166-012F-24021511-upgradeMe%20-RB%20286%20C.zigbee",
"imageType": 303,
"manufacturerCode": 4454,
"sha512": "3195366686f563306fa7fd9d41656498fb6d15e085d4f691d8464f6de074c1042ed33a6706deea6d9dd001ef535f74cd8dceae1deec38194ab1e3d92a596a11f",
Expand All @@ -1981,7 +1981,7 @@
"fileName": "1166-0130-22151511-upgradeMe RS 232 C 20230714.ota",
"fileVersion": 571806993,
"fileSize": 319518,
"url": "https://github.com/Koenkk/zigbee-OTA/raw/master/images/Innr/1166-0130-22151511-upgradeMe RS 232 C 20230714.ota",
"url": "https://github.com/Koenkk/zigbee-OTA/raw/master/images/Innr/1166-0130-22151511-upgradeMe%20%20RS%20232%20C%2020230714.ota",
"imageType": 304,
"manufacturerCode": 4454,
"sha512": "cfe7aab8c926345f38aa817a6ac652519cd891eeba8162e680b98dc91e6025ff150a04e618c8abc5528110965d1bf036f324619269d33bb97a535ce766b71a5f",
Expand All @@ -1991,7 +1991,7 @@
"fileName": "1166-0131-24081511-upgradeMe RB 255 C 20230714.ota",
"fileVersion": 604509457,
"fileSize": 319414,
"url": "https://github.com/Koenkk/zigbee-OTA/raw/master/images/Innr/1166-0131-24081511-upgradeMe RB 255 C 20230714.ota",
"url": "https://github.com/Koenkk/zigbee-OTA/raw/master/images/Innr/1166-0131-24081511-upgradeMe%20%20RB%20255%20C%2020230714.ota",
"imageType": 305,
"manufacturerCode": 4454,
"sha512": "0d1374689790b7d92eecc068303f87ef0d5df1aadddb0a498c9dca73db9313b2239be14b4b63420660da8512a692909cce64b6ff74769fa62bc4fef610c9c366",
Expand Down Expand Up @@ -2081,7 +2081,7 @@
"fileName": "1166-022D-24031511-upgradeMe-BY 266.zigbee",
"fileVersion": 604181777,
"fileSize": 262013,
"url": "https://github.com/Koenkk/zigbee-OTA/raw/master/images/Innr/1166-022D-24031511-upgradeMe-BY 266.zigbee",
"url": "https://github.com/Koenkk/zigbee-OTA/raw/master/images/Innr/1166-022D-24031511-upgradeMe-BY%20266.zigbee",
"imageType": 557,
"manufacturerCode": 4454,
"sha512": "e3a75926cd6e19441dac4aec5a6c81aba32c0fc09fb74481cb1140e4284954497167ae2a897346d53b5cd14bb80bb52b6f14bf7356d5de300b1868f62b6ca8e7",
Expand All @@ -2091,7 +2091,7 @@
"fileName": "1166-022F-24021511-upgradeMe BY 286 C.zigbee",
"fileVersion": 604116241,
"fileSize": 302698,
"url": "https://github.com/Koenkk/zigbee-OTA/raw/master/images/Innr/1166-022F-24021511-upgradeMe BY 286 C.zigbee",
"url": "https://github.com/Koenkk/zigbee-OTA/raw/master/images/Innr/1166-022F-24021511-upgradeMe%20BY%20286%20C.zigbee",
"imageType": 559,
"manufacturerCode": 4454,
"sha512": "a6fdd9ab0f770665e126920143da7c0f66ef5d9fed5f2b76f030c4d21a51ae02d881ca31aa6cb80730246311f8bbaac2f9196b7840ac8bc99a6f22db738e9a00",
Expand Down Expand Up @@ -5163,7 +5163,7 @@
"fileName": "NAMRON_AS_4512737(6001) V22.ota",
"fileVersion": 22,
"fileSize": 245148,
"url": "https://github.com/Koenkk/zigbee-OTA/raw/master/images/Namron/NAMRON_AS_4512737(6001) V22.ota",
"url": "https://github.com/Koenkk/zigbee-OTA/raw/master/images/Namron/NAMRON_AS_4512737(6001)%20V22.ota",
"imageType": 6001,
"manufacturerCode": 4644,
"sha512": "ce40cfc670692384590fc58b84fd9b0d1a6f7b1fa28c6a34ea46fd404b536135151e0fa70bef5ff0c1eeca3fe0d27174806fd1b4863e5bc10afaeca49e0b14f0",
Expand All @@ -5174,7 +5174,7 @@
"fileName": "NAMRON_AS_4512738(6002) V22.ota",
"fileVersion": 22,
"fileSize": 245148,
"url": "https://github.com/Koenkk/zigbee-OTA/raw/master/images/Namron/NAMRON_AS_4512738(6002) V22.ota",
"url": "https://github.com/Koenkk/zigbee-OTA/raw/master/images/Namron/NAMRON_AS_4512738(6002)%20V22.ota",
"imageType": 6002,
"manufacturerCode": 4644,
"sha512": "c6eb11b68bbbacee5ee8dc483a93d07db60003a8345fdd512e05603b9ab1b3dd06f692e01a3be71f3411fdd43a3446198fc7dc806c9b80cab3c86226a41941a7",
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
"format:check": "prettier --check .",
"eslint": "eslint . --max-warnings=0",
"test": "jest test --config=./tests/jest.config.ts --silent --runInBand",
"test:watch": "jest test --watch --config=./tests/jest.config.ts --silent --runInBand",
"coverage": "jest test --config=./tests/jest.config.ts --silent --runInBand --coverage"
},
"keywords": [
Expand Down
2 changes: 1 addition & 1 deletion src/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
21 changes: 13 additions & 8 deletions src/ghw_reprocess_all_images.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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}.`);
Expand Down Expand Up @@ -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);
7 changes: 3 additions & 4 deletions tests/ghw_reprocess_all_images.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -366,13 +366,12 @@ describe('Github Workflow: Re-Process All Images', () => {
const fileName = oldMetas.url.split('/').pop()!;
const newName = fileName.replace('.ota', `(%1).ota`);
const baseUrl = oldMetas.url.replace(fileName, '');
oldMetas.url = baseUrl + escape(newName);
oldMetas.url = baseUrl + encodeURIComponent(newName);
setManifest(common.BASE_INDEX_MANIFEST_FILENAME, [oldMetas]);
const imagePath = useImage(IMAGE_V14_1, BASE_IMAGES_TEST_DIR_PATH);
const baseName = path.basename(imagePath.filename);
const renamedPath = imagePath.filename.replace(baseName, newName);
renameSync(imagePath.filename, renamedPath);
console.log(newName, oldMetas.url, renamedPath);

// @ts-expect-error mocked as needed
await reProcessAllImages(github, core, context, true, true);
Expand All @@ -384,7 +383,7 @@ describe('Github Workflow: Re-Process All Images', () => {
const outManifestMetas = withExtraMetas(
IMAGE_V14_1_METAS,
// @ts-expect-error override
{fileName: newName, url: `${baseUrl}${newName}`},
{fileName: newName, url: `${baseUrl}${encodeURIComponent(newName)}`},
);
delete outManifestMetas.originalUrl;
expect(writeManifestSpy).toHaveBeenNthCalledWith(2, common.BASE_INDEX_MANIFEST_FILENAME, [outManifestMetas]);
Expand Down Expand Up @@ -752,7 +751,7 @@ describe('Github Workflow: Re-Process All Images', () => {
const fileName = oldMetas.url.split('/').pop()!;
const newName = fileName.replace('.ota', `(%1).ota`);
const baseUrl = oldMetas.url.replace(fileName, '');
oldMetas.url = baseUrl + escape(newName);
oldMetas.url = baseUrl + encodeURIComponent(newName);
// @ts-expect-error old metas
setManifest(common.BASE_INDEX_MANIFEST_FILENAME, [oldMetas]);
// link back to existing image from fetch
Expand Down