1
0
mirror of https://github.com/simple-icons/simple-icons.git synced 2024-11-16 00:59:07 +02:00

Avoid raw asset URLs (#11785)

This commit is contained in:
LitoMore 2024-09-18 04:17:47 +08:00 committed by GitHub
parent b1d67ef6e3
commit ef1d49b94e
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 47 additions and 17 deletions

View File

@ -2796,7 +2796,7 @@
{
"title": "Carrefour",
"hex": "004E9F",
"source": "https://upload.wikimedia.org/wikipedia/commons/5/5b/Carrefour_logo.svg"
"source": "https://en.wikipedia.org/wiki/File:Carrefour_logo_no_tag.svg"
},
{
"title": "Carto",
@ -3276,7 +3276,7 @@
{
"title": "Coca Cola",
"hex": "D00013",
"source": "https://upload.wikimedia.org/wikipedia/commons/c/ce/Coca-Cola_logo.svg"
"source": "https://commons.wikimedia.org/wiki/File:Coca-Cola_logo.svg"
},
{
"title": "Cockpit",
@ -3941,12 +3941,12 @@
{
"title": "DaisyUI",
"hex": "5A0EF8",
"source": "https://raw.githubusercontent.com/saadeghi/files/main/daisyui/logo-4.svg"
"source": "https://github.com/saadeghi/files/blob/5c82a1f4428b7c0af6ecfe921a424ebc9d92dc2c/daisyui/logo-4.svg"
},
{
"title": "Dapr",
"hex": "0D2192",
"source": "https://raw.githubusercontent.com/dapr/dapr/18575823c74318c811d6cd6f57ffac76d5debe93/img/dapr_logo.svg"
"source": "https://github.com/dapr/dapr/blob/18575823c74318c811d6cd6f57ffac76d5debe93/img/dapr_logo.svg"
},
{
"title": "Dark Reader",
@ -5860,7 +5860,7 @@
{
"title": "Game & Watch",
"hex": "000000",
"source": "https://upload.wikimedia.org/wikipedia/commons/4/41/Game_and_watch_logo.svg"
"source": "https://commons.wikimedia.org/wiki/File:Game_and_watch_logo.svg"
},
{
"title": "Game Developer",
@ -6492,7 +6492,7 @@
{
"title": "Google Maps",
"hex": "4285F4",
"source": "https://upload.wikimedia.org/wikipedia/commons/a/a9/Google_Maps_icon.svg"
"source": "https://commons.wikimedia.org/wiki/File:Google_Maps_icon.svg"
},
{
"title": "Google Marketing Platform",

View File

@ -11,6 +11,7 @@
* @typedef {IconData[]} IconsData
*/
import path from 'node:path';
import process from 'node:process';
import fakeDiff from 'fake-diff';
import {collator, getIconsDataString, normalizeNewlines} from '../../sdk.mjs';
@ -88,13 +89,27 @@ const TESTS = {
checkUrl(data) {
/**
* Check if an URL has a redundant trailing slash.
* @param {string} url URL to check
* @param {URL} $url URL instance
* @param {string} url Original URL string
* @returns {boolean} Whether the URL has a redundant trailing slash
*/
const hasRedundantTrailingSlash = (url) => {
const {origin} = new global.URL(url);
return /^\/+$/.test(url.replace(origin, ''));
};
const hasRedundantTrailingSlash = ($url, url) => url === $url.origin + '/';
/**
* Check if an URL is static wikimedia asset URL.
* @param {URL} $url URL instance
* @returns {boolean} Whether the URL is static wikimedia asset URL
*/
const isStaticWikimediaAssetUrl = ($url) =>
$url.hostname === 'upload.wikimedia.org';
/**
* Check if an URL is raw GitHub asset URL.
* @param {string} $url URL instance
* @returns {boolean} Whether the URL is raw GitHub asset URL
*/
const isRawGithubAssetUrl = ($url) =>
$url.hostname === 'raw.githubusercontent.com';
const allUrlFields = [
...new Set(
@ -117,14 +132,29 @@ const TESTS = {
),
];
const invalidUrls = allUrlFields.filter((url) =>
hasRedundantTrailingSlash(url),
);
const invalidUrls = [];
for (const url of allUrlFields) {
const $url = new global.URL(url);
if (hasRedundantTrailingSlash($url, url)) {
invalidUrls.push(fakeDiff(url, $url.origin));
}
if (isStaticWikimediaAssetUrl($url)) {
const expectedUrl = `https://commons.wikimedia.org/wiki/File:${path.basename($url.pathname)}`;
invalidUrls.push(fakeDiff(url, expectedUrl));
}
if (isRawGithubAssetUrl($url)) {
// https://github.com/LitoMore/simple-icons-cdn/blob/main/media/imgcat-screenshot.webp
const [, owner, repo, hash, ...directory] = $url.pathname.split('/');
const expectedUrl = `https://github.com/${owner}/${repo}/blob/${hash}/${directory.join('/')}`;
invalidUrls.push(fakeDiff(url, expectedUrl));
}
}
if (invalidUrls.length > 0) {
return `Some URLs have a redundant trailing slash:\n\n${invalidUrls.join(
'\n',
)}`;
return `Invalid URLs:\n\n${invalidUrls.join('\n\n')}`;
}
},
};