Merge pull request #16213 from Snuffleupagus/validateCSSFont-quotes
Reduce duplication in the `validateCSSFont` helper function
This commit is contained in:
commit
d584513cb2
@ -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