Commit 121a6b32 authored by Ryan VanderMeulen's avatar Ryan VanderMeulen
Browse files

Bug 1663803 - Cherry-pick some upstream forms fixes to Firefox 81. r=bdahl, a=RyanVM

This is a cherry-pick of the following upstream commits:
https://github.com/mozilla/pdf.js/pull/12344
https://github.com/mozilla/pdf.js/pull/12345

Differential Revision: https://phabricator.services.mozilla.com/D89538
parent d9fe3ea8
......@@ -336,7 +336,7 @@ var _text_layer = __w_pdfjs_require__(20);
var _svg = __w_pdfjs_require__(21);
const pdfjsVersion = '2.6.324';
const pdfjsBuild = 'eb3654e2';
const pdfjsBuild = 'eb3654e27';
;
/***/ }),
......@@ -853,6 +853,7 @@ exports.assert = assert;
exports.bytesToString = bytesToString;
exports.createPromiseCapability = createPromiseCapability;
exports.escapeString = escapeString;
exports.encodeToXmlString = encodeToXmlString;
exports.getModificationDate = getModificationDate;
exports.getVerbosityLevel = getVerbosityLevel;
exports.info = info;
......@@ -863,6 +864,7 @@ exports.isNum = isNum;
exports.isString = isString;
exports.isSameOrigin = isSameOrigin;
exports.createValidAbsoluteUrl = createValidAbsoluteUrl;
exports.parseXFAPath = parseXFAPath;
exports.removeNullCharacters = removeNullCharacters;
exports.setVerbosityLevel = setVerbosityLevel;
exports.shadow = shadow;
......@@ -1668,6 +1670,77 @@ const createObjectURL = function createObjectURLClosure() {
exports.createObjectURL = createObjectURL;
function parseXFAPath(path) {
const positionPattern = /(.+)\[([0-9]+)\]$/;
return path.split(".").map(component => {
const m = component.match(positionPattern);
if (m) {
return {
name: m[1],
pos: parseInt(m[2], 10)
};
}
return {
name: component,
pos: 0
};
});
}
const XMLEntities = {
0x3c: "<",
0x3e: ">",
0x26: "&",
0x22: """,
0x27: "'"
};
function encodeToXmlString(str) {
const buffer = [];
let start = 0;
for (let i = 0, ii = str.length; i < ii; i++) {
const char = str.codePointAt(i);
if (0x20 <= char && char <= 0x7e) {
const entity = XMLEntities[char];
if (entity) {
if (start < i) {
buffer.push(str.substring(start, i));
}
buffer.push(entity);
start = i + 1;
}
} else {
if (start < i) {
buffer.push(str.substring(start, i));
}
buffer.push(`&#x${char.toString(16).toUpperCase()};`);
if (char > 0xd7ff && (char < 0xe000 || char > 0xfffd)) {
i++;
}
start = i + 1;
}
}
if (buffer.length === 0) {
return str;
}
if (start < str.length) {
buffer.push(str.substring(start, str.length));
}
return buffer.join("");
}
/***/ }),
/* 3 */
/***/ (function(module, exports, __w_pdfjs_require__) {
......@@ -3839,7 +3912,7 @@ const InternalRenderTask = function InternalRenderTaskClosure() {
const version = '2.6.324';
exports.version = version;
const build = 'eb3654e2';
const build = 'eb3654e27';
exports.build = build;
/***/ }),
......@@ -7568,7 +7641,10 @@ exports.Metadata = Metadata;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.SimpleXMLParser = void 0;
exports.SimpleXMLParser = exports.SimpleDOMNode = void 0;
var _util = __w_pdfjs_require__(2);
const XMLParserErrorCode = {
NoError: 0,
EndOfDocument: -1,
......@@ -7602,9 +7678,9 @@ class XMLParserBase {
_resolveEntities(s) {
return s.replace(/&([^;]+);/g, (all, entity) => {
if (entity.substring(0, 2) === "#x") {
return String.fromCharCode(parseInt(entity.substring(2), 16));
return String.fromCodePoint(parseInt(entity.substring(2), 16));
} else if (entity.substring(0, 1) === "#") {
return String.fromCharCode(parseInt(entity.substring(1), 10));
return String.fromCodePoint(parseInt(entity.substring(1), 10));
}
switch (entity) {
......@@ -7909,14 +7985,107 @@ class SimpleDOMNode {
return this.childNodes && this.childNodes.length > 0;
}
searchNode(paths, pos) {
if (pos >= paths.length) {
return this;
}
const component = paths[pos];
const stack = [];
let node = this;
while (true) {
if (component.name === node.nodeName) {
if (component.pos === 0) {
const res = node.searchNode(paths, pos + 1);
if (res !== null) {
return res;
}
} else if (stack.length === 0) {
return null;
} else {
const [parent] = stack.pop();
let siblingPos = 0;
for (const child of parent.childNodes) {
if (component.name === child.nodeName) {
if (siblingPos === component.pos) {
return child.searchNode(paths, pos + 1);
}
siblingPos++;
}
}
return node.searchNode(paths, pos + 1);
}
}
if (node.childNodes && node.childNodes.length !== 0) {
stack.push([node, 0]);
node = node.childNodes[0];
} else if (stack.length === 0) {
return null;
} else {
while (stack.length !== 0) {
const [parent, currentPos] = stack.pop();
const newPos = currentPos + 1;
if (newPos < parent.childNodes.length) {
stack.push([parent, newPos]);
node = parent.childNodes[newPos];
break;
}
}
if (stack.length === 0) {
return null;
}
}
}
}
dump(buffer) {
if (this.nodeName === "#text") {
buffer.push((0, _util.encodeToXmlString)(this.nodeValue));
return;
}
buffer.push(`<${this.nodeName}`);
if (this.attributes) {
for (const attribute of this.attributes) {
buffer.push(` ${attribute.name}=\"${(0, _util.encodeToXmlString)(attribute.value)}\"`);
}
}
if (this.hasChildNodes()) {
buffer.push(">");
for (const child of this.childNodes) {
child.dump(buffer);
}
buffer.push(`</${this.nodeName}>`);
} else if (this.nodeValue) {
buffer.push(`>${(0, _util.encodeToXmlString)(this.nodeValue)}</${this.nodeName}>`);
} else {
buffer.push("/>");
}
}
}
exports.SimpleDOMNode = SimpleDOMNode;
class SimpleXMLParser extends XMLParserBase {
constructor() {
constructor(hasAttributes = false) {
super();
this._currentFragment = null;
this._stack = null;
this._errorCode = XMLParserErrorCode.NoError;
this._hasAttributes = hasAttributes;
}
parseFromString(data) {
......@@ -7969,6 +8138,10 @@ class SimpleXMLParser extends XMLParserBase {
const node = new SimpleDOMNode(name);
node.childNodes = [];
if (this._hasAttributes) {
node.attributes = attributes;
}
this._currentFragment.push(node);
if (isEmpty) {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment