mirror of
https://github.com/mozilla/pdf.js.git
synced 2025-04-25 17:48:07 +02:00
Merge pull request #13961 from Snuffleupagus/simpler-regexp
Simplify some regular expressions
This commit is contained in:
commit
680f33c31c
8 changed files with 35 additions and 38 deletions
|
@ -208,7 +208,7 @@ function isWhiteSpace(ch) {
|
|||
* each part of the path.
|
||||
*/
|
||||
function parseXFAPath(path) {
|
||||
const positionPattern = /(.+)\[([0-9]+)\]$/;
|
||||
const positionPattern = /(.+)\[(\d+)\]$/;
|
||||
return path.split(".").map(component => {
|
||||
const m = component.match(positionPattern);
|
||||
if (m) {
|
||||
|
@ -428,10 +428,7 @@ function validateCSSFont(cssFontInfo) {
|
|||
} else {
|
||||
// See https://developer.mozilla.org/en-US/docs/Web/CSS/custom-ident.
|
||||
for (const ident of fontFamily.split(/[ \t]+/)) {
|
||||
if (
|
||||
/^([0-9]|(-([0-9]|-)))/.test(ident) ||
|
||||
!/^[a-zA-Z0-9\-_\\]+$/.test(ident)
|
||||
) {
|
||||
if (/^(\d|(-(\d|-)))/.test(ident) || !/^[\w-\\]+$/.test(ident)) {
|
||||
warn(
|
||||
`XFA - FontFamily contains some invalid <custom-ident>: ${fontFamily}.`
|
||||
);
|
||||
|
|
|
@ -576,7 +576,7 @@ const FINGERPRINT_FIRST_BYTES = 1024;
|
|||
const EMPTY_FINGERPRINT =
|
||||
"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00";
|
||||
|
||||
const PDF_HEADER_VERSION_REGEXP = /^[1-9]\.[0-9]$/;
|
||||
const PDF_HEADER_VERSION_REGEXP = /^[1-9]\.\d$/;
|
||||
|
||||
function find(stream, signature, limit = 1024, backwards = false) {
|
||||
if (
|
||||
|
@ -988,7 +988,7 @@ class PDFDocument {
|
|||
}
|
||||
let fontFamily = descriptor.get("FontFamily");
|
||||
// For example, "Wingdings 3" is not a valid font name in the css specs.
|
||||
fontFamily = fontFamily.replace(/[ ]+([0-9])/g, "$1");
|
||||
fontFamily = fontFamily.replace(/[ ]+(\d)/g, "$1");
|
||||
const fontWeight = descriptor.get("FontWeight");
|
||||
|
||||
// Angle is expressed in degrees counterclockwise in PDF
|
||||
|
|
|
@ -117,8 +117,8 @@ const TOKEN = {
|
|||
};
|
||||
|
||||
const hexPattern = /^[uU]([0-9a-fA-F]{4,8})/;
|
||||
const numberPattern = /^[0-9]*(?:\.[0-9]*)?(?:[Ee][+-]?[0-9]+)?/;
|
||||
const dotNumberPattern = /^[0-9]*(?:[Ee][+-]?[0-9]+)?/;
|
||||
const numberPattern = /^\d*(?:\.\d*)?(?:[Ee][+-]?\d+)?/;
|
||||
const dotNumberPattern = /^\d*(?:[Ee][+-]?\d+)?/;
|
||||
const eolPattern = /[\r\n]+/;
|
||||
const identifierPattern = new RegExp("^[\\p{L}_$!][\\p{L}\\p{N}_$]*", "u");
|
||||
|
||||
|
|
|
@ -657,7 +657,7 @@ class Barcode extends XFAObject {
|
|||
"shift-jis",
|
||||
"ucs-2",
|
||||
"utf-16",
|
||||
].includes(k) || k.match(/iso-8859-[0-9]{2}/),
|
||||
].includes(k) || k.match(/iso-8859-\d{2}/),
|
||||
});
|
||||
this.checksum = getStringOption(attributes.checksum, [
|
||||
"none",
|
||||
|
@ -5274,7 +5274,7 @@ class Submit extends XFAObject {
|
|||
"shift-jis",
|
||||
"ucs-2",
|
||||
"utf-16",
|
||||
].includes(k) || k.match(/iso-8859-[0-9]{2}/),
|
||||
].includes(k) || k.match(/iso-8859-\d{2}/),
|
||||
});
|
||||
this.use = attributes.use || "";
|
||||
this.usehref = attributes.usehref || "";
|
||||
|
|
|
@ -22,7 +22,7 @@ const dimConverters = {
|
|||
in: x => x * 72,
|
||||
px: x => x,
|
||||
};
|
||||
const measurementPattern = /([+-]?[0-9]+\.?[0-9]*)(.*)/;
|
||||
const measurementPattern = /([+-]?\d+\.?\d*)(.*)/;
|
||||
|
||||
function stripQuotes(str) {
|
||||
if (str.startsWith("'") || str.startsWith('"')) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue