mirror of https://github.com/iconify/api.git
chore: clean up params in svg query
This commit is contained in:
parent
65b0eca32e
commit
f62b8ba8e6
|
|
@ -0,0 +1,6 @@
|
||||||
|
/**
|
||||||
|
* Basic cleanup for parameters
|
||||||
|
*/
|
||||||
|
export function cleanupQueryValue(value: string | undefined) {
|
||||||
|
return value ? value.replace(/['"<>&]/g, '') : undefined;
|
||||||
|
}
|
||||||
|
|
@ -6,6 +6,7 @@ import { getStoredIconsData } from '../../data/icon-set/utils/get-icons.js';
|
||||||
import { iconSets } from '../../data/icon-sets.js';
|
import { iconSets } from '../../data/icon-sets.js';
|
||||||
import { paramToBoolean } from '../../misc/bool.js';
|
import { paramToBoolean } from '../../misc/bool.js';
|
||||||
import { errorText } from '../helpers/errors.js';
|
import { errorText } from '../helpers/errors.js';
|
||||||
|
import { cleanupQueryValue } from '../helpers/query.js';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Check selector for weird stuff
|
* Check selector for weird stuff
|
||||||
|
|
@ -57,7 +58,7 @@ export function generateIconsStyleResponse(prefix: string, query: FastifyRequest
|
||||||
|
|
||||||
// 'color': string
|
// 'color': string
|
||||||
// Sets color for monotone images
|
// Sets color for monotone images
|
||||||
const color = qOptions.color;
|
const color = cleanupQueryValue(qOptions.color);
|
||||||
if (typeof color === 'string' && stringToColor(color)) {
|
if (typeof color === 'string' && stringToColor(color)) {
|
||||||
options.color = color;
|
options.color = color;
|
||||||
}
|
}
|
||||||
|
|
@ -98,7 +99,7 @@ export function generateIconsStyleResponse(prefix: string, query: FastifyRequest
|
||||||
// 'commonSelector': string
|
// 'commonSelector': string
|
||||||
// Common selector for all requested icons
|
// Common selector for all requested icons
|
||||||
// Alias: 'common'
|
// Alias: 'common'
|
||||||
const commonSelector = qOptions.commonSelector || q.common;
|
const commonSelector = cleanupQueryValue(qOptions.commonSelector || q.common);
|
||||||
if (checkSelector(commonSelector)) {
|
if (checkSelector(commonSelector)) {
|
||||||
options.commonSelector = commonSelector;
|
options.commonSelector = commonSelector;
|
||||||
}
|
}
|
||||||
|
|
@ -106,7 +107,7 @@ export function generateIconsStyleResponse(prefix: string, query: FastifyRequest
|
||||||
// 'iconSelector': string
|
// 'iconSelector': string
|
||||||
// Icon selector
|
// Icon selector
|
||||||
// Alias: 'selector'
|
// Alias: 'selector'
|
||||||
const iconSelector = qOptions.iconSelector || q.selector;
|
const iconSelector = cleanupQueryValue(qOptions.iconSelector || q.selector);
|
||||||
if (checkSelector(iconSelector)) {
|
if (checkSelector(iconSelector)) {
|
||||||
options.iconSelector = iconSelector;
|
options.iconSelector = iconSelector;
|
||||||
}
|
}
|
||||||
|
|
@ -114,7 +115,7 @@ export function generateIconsStyleResponse(prefix: string, query: FastifyRequest
|
||||||
// 'overrideSelector': string
|
// 'overrideSelector': string
|
||||||
// Selector for rules in icon that override common rules
|
// Selector for rules in icon that override common rules
|
||||||
// Alias: 'override'
|
// Alias: 'override'
|
||||||
const overrideSelector = qOptions.overrideSelector || q.override;
|
const overrideSelector = cleanupQueryValue(qOptions.overrideSelector || q.override);
|
||||||
if (checkSelector(overrideSelector)) {
|
if (checkSelector(overrideSelector)) {
|
||||||
options.overrideSelector = overrideSelector;
|
options.overrideSelector = overrideSelector;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -8,6 +8,7 @@ import type { FastifyReply, FastifyRequest } from 'fastify';
|
||||||
import { getStoredIconData } from '../../data/icon-set/utils/get-icon.js';
|
import { getStoredIconData } from '../../data/icon-set/utils/get-icon.js';
|
||||||
import { iconSets } from '../../data/icon-sets.js';
|
import { iconSets } from '../../data/icon-sets.js';
|
||||||
import { errorText } from '../helpers/errors.js';
|
import { errorText } from '../helpers/errors.js';
|
||||||
|
import { cleanupQueryValue } from '../helpers/query.js';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Generate SVG
|
* Generate SVG
|
||||||
|
|
@ -43,8 +44,8 @@ export function generateSVGResponse(prefix: string, name: string, query: Fastify
|
||||||
const customisations: IconifyIconCustomisations = {};
|
const customisations: IconifyIconCustomisations = {};
|
||||||
|
|
||||||
// Dimensions
|
// Dimensions
|
||||||
customisations.width = q.width || defaultIconCustomisations.width;
|
customisations.width = cleanupQueryValue(q.width) || defaultIconCustomisations.width;
|
||||||
customisations.height = q.height || defaultIconCustomisations.height;
|
customisations.height = cleanupQueryValue(q.height) || defaultIconCustomisations.height;
|
||||||
|
|
||||||
// Rotation
|
// Rotation
|
||||||
customisations.rotate = q.rotate ? rotateFromString(q.rotate, 0) : 0;
|
customisations.rotate = q.rotate ? rotateFromString(q.rotate, 0) : 0;
|
||||||
|
|
@ -75,7 +76,7 @@ export function generateSVGResponse(prefix: string, name: string, query: Fastify
|
||||||
let html = iconToHTML(body, svg.attributes);
|
let html = iconToHTML(body, svg.attributes);
|
||||||
|
|
||||||
// Change color
|
// Change color
|
||||||
const color = q.color;
|
const color = cleanupQueryValue(q.color);
|
||||||
if (color && html.indexOf('currentColor') !== -1 && color.indexOf('"') === -1) {
|
if (color && html.indexOf('currentColor') !== -1 && color.indexOf('"') === -1) {
|
||||||
html = html.split('currentColor').join(color);
|
html = html.split('currentColor').join(color);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue