Reduce duplication in the validateCSSFont
helper function
Currently we're *virtually* duplicating the same code, for validating quotation marks, twice in this helper function. The size decrease is quite small (107 bytes) and this makes the code slightly harder to reader, hence I completely understand if this patch is rejected.
This commit is contained in:
parent
8a2dfdb032
commit
ef70988027
@ -470,14 +470,11 @@ function validateCSSFont(cssFontInfo) {
|
|||||||
const { fontFamily, fontWeight, italicAngle } = cssFontInfo;
|
const { fontFamily, fontWeight, italicAngle } = cssFontInfo;
|
||||||
|
|
||||||
// See https://developer.mozilla.org/en-US/docs/Web/CSS/string.
|
// See https://developer.mozilla.org/en-US/docs/Web/CSS/string.
|
||||||
if (/^".*"$/.test(fontFamily)) {
|
const m = /^("|').*("|')$/.exec(fontFamily);
|
||||||
if (/[^\\]"/.test(fontFamily.slice(1, -1))) {
|
if (m && m[1] === m[2]) {
|
||||||
warn(`XFA - FontFamily contains some unescaped ": ${fontFamily}.`);
|
const re = new RegExp(`[^\\\\]${m[1]}`);
|
||||||
return false;
|
if (re.test(fontFamily.slice(1, -1))) {
|
||||||
}
|
warn(`XFA - FontFamily contains unescaped ${m[1]}: ${fontFamily}.`);
|
||||||
} else if (/^'.*'$/.test(fontFamily)) {
|
|
||||||
if (/[^\\]'/.test(fontFamily.slice(1, -1))) {
|
|
||||||
warn(`XFA - FontFamily contains some unescaped ': ${fontFamily}.`);
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
@ -485,7 +482,7 @@ function validateCSSFont(cssFontInfo) {
|
|||||||
for (const ident of fontFamily.split(/[ \t]+/)) {
|
for (const ident of fontFamily.split(/[ \t]+/)) {
|
||||||
if (/^(\d|(-(\d|-)))/.test(ident) || !/^[\w-\\]+$/.test(ident)) {
|
if (/^(\d|(-(\d|-)))/.test(ident) || !/^[\w-\\]+$/.test(ident)) {
|
||||||
warn(
|
warn(
|
||||||
`XFA - FontFamily contains some invalid <custom-ident>: ${fontFamily}.`
|
`XFA - FontFamily contains invalid <custom-ident>: ${fontFamily}.`
|
||||||
);
|
);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user