1
0
mirror of https://github.com/simple-icons/simple-icons.git synced 2024-12-16 01:10:30 +02:00

Ensure that icon paths start with moveto command (#5069)

This commit is contained in:
Álvaro Mondéjar 2021-02-22 17:20:07 +01:00 committed by GitHub
parent 4423505062
commit 078ad4d714
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 34 additions and 1 deletions

View File

@ -473,6 +473,40 @@ module.exports = {
ignoreIcon(reporter.name, iconPath, $);
}
}
},
function(reporter, $, ast) {
reporter.name = "path-format";
const iconPath = $.find("path").attr("d");
const validPathFormatRegex = /^[Mm][MmZzLlHhVvCcSsQqTtAaEe0-9-,.\s]+$/;
if (!validPathFormatRegex.test(iconPath)) {
let errorMsg = "Invalid path format", reason;
if (!(/^[Mm]/.test(iconPath))) {
// doesn't start with moveto
reason = `should start with \"moveto\" command (\"M\" or \"m\"), but starts with \"${iconPath[0]}\"`;
reporter.error(`${errorMsg}: ${reason}`);
}
const validPathCharacters = "MmZzLlHhVvCcSsQqTtAaEe0123456789-,. ",
invalidCharactersMsgs = [],
pathDStart = '<path d="',
pathDIndex = $.html().indexOf(pathDStart) + pathDStart.length;
for (let [i, char] of Object.entries(iconPath)) {
if (validPathCharacters.indexOf(char) === -1) {
invalidCharactersMsgs.push(`"${char}" at index ${pathDIndex + parseInt(i)}`);
}
}
// contains invalid characters
if (invalidCharactersMsgs.length > 0) {
reason = `unexpected character${invalidCharactersMsgs.length > 1 ? 's' : ''} found`;
reason += ` (${invalidCharactersMsgs.join(", ")})`;
reporter.error(`${errorMsg}: ${reason}`);
}
}
}
]
}

View File

@ -24,7 +24,6 @@ icons.forEach(icon => {
test(`${icon.title} has a "path"`, () => {
expect(typeof subject.path).toBe('string');
expect(subject.path).toMatch(/[MmZzLlHhVvCcSsQqTtAaEe0-9-,.\s]/g);
});
test(`${icon.title} has a "slug"`, () => {