Merge pull request #19662 from Snuffleupagus/xfa-rm-regex

Replace a few simple regular expressions in the XFA-code with string parsing
This commit is contained in:
Jonas Jenwald 2025-03-15 19:44:30 +01:00 committed by GitHub
commit d1d88cc09e
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 10 additions and 19 deletions

View File

@ -956,8 +956,7 @@ class Range extends ContentObject {
[$finalize]() { [$finalize]() {
this[$content] = this[$content] this[$content] = this[$content]
.trim() .split(",", 2)
.split(/\s*,\s*/, 2)
.map(range => range.split("-").map(x => parseInt(x.trim(), 10))) .map(range => range.split("-").map(x => parseInt(x.trim(), 10)))
.filter(range => range.every(x => !isNaN(x))) .filter(range => range.every(x => !isNaN(x)))
.map(range => { .map(range => {
@ -1308,10 +1307,7 @@ class Window extends ContentObject {
} }
[$finalize]() { [$finalize]() {
const pair = this[$content] const pair = this[$content].split(",", 2).map(x => parseInt(x.trim(), 10));
.trim()
.split(/\s*,\s*/, 2)
.map(x => parseInt(x, 10));
if (pair.some(x => isNaN(x))) { if (pair.some(x => isNaN(x))) {
this[$content] = [0, 0]; this[$content] = [0, 0];
return; return;

View File

@ -106,9 +106,8 @@ function getRatio(data) {
return { num: 1, den: 1 }; return { num: 1, den: 1 };
} }
const ratio = data const ratio = data
.trim() .split(":", 2)
.split(/\s*:\s*/) .map(x => parseFloat(x.trim()))
.map(x => parseFloat(x))
.filter(x => !isNaN(x)); .filter(x => !isNaN(x));
if (ratio.length === 1) { if (ratio.length === 1) {
ratio.push(1); ratio.push(1);
@ -141,8 +140,7 @@ function getColor(data, def = [0, 0, 0]) {
return { r, g, b }; return { r, g, b };
} }
const color = data const color = data
.trim() .split(",", 3)
.split(/\s*,\s*/)
.map(c => MathClamp(parseInt(c.trim(), 10), 0, 255)) .map(c => MathClamp(parseInt(c.trim(), 10), 0, 255))
.map(c => (isNaN(c) ? 0 : c)); .map(c => (isNaN(c) ? 0 : c));
@ -159,10 +157,8 @@ function getBBox(data) {
if (!data) { if (!data) {
return { x: def, y: def, width: def, height: def }; return { x: def, y: def, width: def, height: def };
} }
const bbox = data const bbox = data.split(",", 4).map(m => getMeasurement(m.trim(), "-1"));
.trim()
.split(/\s*,\s*/)
.map(m => getMeasurement(m, "-1"));
if (bbox.length < 4 || bbox[2] < 0 || bbox[3] < 0) { if (bbox.length < 4 || bbox[2] < 0 || bbox[3] < 0) {
return { x: def, y: def, width: def, height: def }; return { x: def, y: def, width: def, height: def };
} }

View File

@ -191,10 +191,9 @@ function checkStyle(node) {
// Remove any non-allowed keys. // Remove any non-allowed keys.
return node.style return node.style
.trim() .split(";")
.split(/\s*;\s*/) .filter(s => !!s.trim())
.filter(s => !!s) .map(s => s.split(":", 2).map(t => t.trim()))
.map(s => s.split(/\s*:\s*/, 2))
.filter(([key, value]) => { .filter(([key, value]) => {
if (key === "font-family") { if (key === "font-family") {
node[$globalData].usedTypefaces.add(value); node[$globalData].usedTypefaces.add(value);