Update utils.js
This commit is contained in:
parent
afa59521fa
commit
2be472b941
1 changed files with 4 additions and 11 deletions
15
src/utils.js
15
src/utils.js
|
@ -198,27 +198,22 @@ function getFontPbf(allowedFonts, fontPath, name, range, fallbacks) {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
if (!allowedFonts || (allowedFonts[name] && fallbacks)) {
|
if (!allowedFonts || (allowedFonts[name] && fallbacks)) {
|
||||||
const fontMatch = name?.match(/^[\w\s-]+$/);
|
const fontMatch = name?.match(/^[\w\s-]+$/);
|
||||||
|
const sanitizedName = fontMatch?.[0] || 'invalid';
|
||||||
if (
|
if (
|
||||||
!name ||
|
!name ||
|
||||||
typeof name !== 'string' ||
|
typeof name !== 'string' ||
|
||||||
name.trim() === '' ||
|
name.trim() === '' ||
|
||||||
!fontMatch
|
!fontMatch
|
||||||
) {
|
) {
|
||||||
console.error('ERROR: Invalid font name: %s', 'invalid');
|
console.error('ERROR: Invalid font name: %s', sanitizedName);
|
||||||
return reject('Invalid font name');
|
return reject('Invalid font name');
|
||||||
}
|
}
|
||||||
const sanitizedName = fontMatch[0];
|
|
||||||
console.error('ERROR: Invalid font name: %s', sanitizedName);
|
|
||||||
if (!/^\d+-\d+$/.test(range)) {
|
if (!/^\d+-\d+$/.test(range)) {
|
||||||
console.error('ERROR: Invalid range: %s', range);
|
console.error('ERROR: Invalid range: %s', range);
|
||||||
return reject('Invalid range');
|
return reject('Invalid range');
|
||||||
}
|
}
|
||||||
const sanitizedFontPath = fontPath.replace(/^(\.\.\/)+/, '');
|
const filename = path.join(fontPath, sanitizedName, `${range}.pbf`);
|
||||||
const filename = path.join(
|
|
||||||
sanitizedFontPath,
|
|
||||||
sanitizedName,
|
|
||||||
`${range}.pbf`,
|
|
||||||
);
|
|
||||||
if (!fallbacks) {
|
if (!fallbacks) {
|
||||||
fallbacks = clone(allowedFonts || {});
|
fallbacks = clone(allowedFonts || {});
|
||||||
}
|
}
|
||||||
|
@ -245,7 +240,6 @@ function getFontPbf(allowedFonts, fontPath, name, range, fallbacks) {
|
||||||
fallbackName = Object.keys(fallbacks)[0];
|
fallbackName = Object.keys(fallbacks)[0];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
console.error(
|
console.error(
|
||||||
`ERROR: Trying to use %s as a fallback for: %s`,
|
`ERROR: Trying to use %s as a fallback for: %s`,
|
||||||
fallbackName,
|
fallbackName,
|
||||||
|
@ -268,7 +262,6 @@ function getFontPbf(allowedFonts, fontPath, name, range, fallbacks) {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Combines multiple font pbf buffers into one.
|
* Combines multiple font pbf buffers into one.
|
||||||
* @param {object} allowedFonts - An object of allowed fonts.
|
* @param {object} allowedFonts - An object of allowed fonts.
|
||||||
|
|
Loading…
Reference in a new issue