XFA - Remove namespace from nodes under xfa:data node
- in real life some xfa contains xml like <xfa:data><xfa:Foo><xfa:Bar>...</xfa:data> since there are no Foo or Bar in the xfa namespace the JS representation are empty and that leads to errors. - so the idea is to make all nodes under xfa:data namespace agnostic which means that ns are removed from nodes in the parser but only xfa:data descendants.
This commit is contained in:
parent
6c9b6bc599
commit
5555114bb3
@ -18,6 +18,7 @@ import {
|
||||
$cleanup,
|
||||
$finalize,
|
||||
$ids,
|
||||
$isNsAgnostic,
|
||||
$nsAttributes,
|
||||
$onChild,
|
||||
$resolvePrototypes,
|
||||
@ -67,6 +68,7 @@ class Empty extends XFAObject {
|
||||
class Builder {
|
||||
constructor() {
|
||||
this._namespaceStack = [];
|
||||
this._nsAgnosticLevel = 0;
|
||||
|
||||
// Each prefix has its own stack
|
||||
this._namespacePrefixes = new Map();
|
||||
@ -118,18 +120,27 @@ class Builder {
|
||||
(namespaceToUse && namespaceToUse[$buildXFAObject](name, attributes)) ||
|
||||
new Empty();
|
||||
|
||||
if (node[$isNsAgnostic]()) {
|
||||
this._nsAgnosticLevel++;
|
||||
}
|
||||
|
||||
// In case the node has some namespace things,
|
||||
// we must pop the different stacks.
|
||||
if (hasNamespaceDef || prefixes) {
|
||||
if (hasNamespaceDef || prefixes || node[$isNsAgnostic]()) {
|
||||
node[$cleanup] = {
|
||||
hasNamespace: hasNamespaceDef,
|
||||
prefixes,
|
||||
nsAgnostic: node[$isNsAgnostic](),
|
||||
};
|
||||
}
|
||||
|
||||
return node;
|
||||
}
|
||||
|
||||
isNsAgnostic() {
|
||||
return this._nsAgnosticLevel > 0;
|
||||
}
|
||||
|
||||
_searchNamespace(nsName) {
|
||||
let ns = this._namespaces.get(nsName);
|
||||
if (ns) {
|
||||
@ -178,7 +189,7 @@ class Builder {
|
||||
}
|
||||
|
||||
clean(data) {
|
||||
const { hasNamespace, prefixes } = data;
|
||||
const { hasNamespace, prefixes, nsAgnostic } = data;
|
||||
if (hasNamespace) {
|
||||
this._currentNamespace = this._namespaceStack.pop();
|
||||
}
|
||||
@ -187,6 +198,9 @@ class Builder {
|
||||
this._namespacePrefixes.get(prefix).pop();
|
||||
});
|
||||
}
|
||||
if (nsAgnostic) {
|
||||
this._nsAgnosticLevel--;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -15,6 +15,7 @@
|
||||
|
||||
import {
|
||||
$appendChild,
|
||||
$isNsAgnostic,
|
||||
$namespaceId,
|
||||
$nodeName,
|
||||
$onChild,
|
||||
@ -29,6 +30,10 @@ class Data extends XmlObject {
|
||||
constructor(attributes) {
|
||||
super(DATASETS_NS_ID, "data", attributes);
|
||||
}
|
||||
|
||||
[$isNsAgnostic]() {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
class Datasets extends XFAObject {
|
||||
|
@ -118,12 +118,12 @@ class XFAParser extends XMLParserBase {
|
||||
return [namespace, prefixes, attributeObj];
|
||||
}
|
||||
|
||||
_getNameAndPrefix(name) {
|
||||
_getNameAndPrefix(name, nsAgnostic) {
|
||||
const i = name.indexOf(":");
|
||||
if (i === -1) {
|
||||
return [name, null];
|
||||
}
|
||||
return [name.substring(i + 1), name.substring(0, i)];
|
||||
return [name.substring(i + 1), nsAgnostic ? "" : name.substring(0, i)];
|
||||
}
|
||||
|
||||
onBeginElement(tagName, attributes, isEmpty) {
|
||||
@ -131,7 +131,10 @@ class XFAParser extends XMLParserBase {
|
||||
attributes,
|
||||
tagName
|
||||
);
|
||||
const [name, nsPrefix] = this._getNameAndPrefix(tagName);
|
||||
const [name, nsPrefix] = this._getNameAndPrefix(
|
||||
tagName,
|
||||
this._builder.isNsAgnostic()
|
||||
);
|
||||
const node = this._builder.build({
|
||||
nsPrefix,
|
||||
name,
|
||||
|
@ -60,6 +60,7 @@ const $isCDATAXml = Symbol();
|
||||
const $isBindable = Symbol();
|
||||
const $isDataValue = Symbol();
|
||||
const $isDescendent = Symbol();
|
||||
const $isNsAgnostic = Symbol();
|
||||
const $isSplittable = Symbol();
|
||||
const $isThereMoreWidth = Symbol();
|
||||
const $isTransparent = Symbol();
|
||||
@ -160,6 +161,10 @@ class XFAObject {
|
||||
);
|
||||
}
|
||||
|
||||
[$isNsAgnostic]() {
|
||||
return false;
|
||||
}
|
||||
|
||||
[$acceptWhitespace]() {
|
||||
return false;
|
||||
}
|
||||
@ -1087,6 +1092,7 @@ export {
|
||||
$isCDATAXml,
|
||||
$isDataValue,
|
||||
$isDescendent,
|
||||
$isNsAgnostic,
|
||||
$isSplittable,
|
||||
$isThereMoreWidth,
|
||||
$isTransparent,
|
||||
|
1
test/pdfs/xfa_bug1721600.pdf.link
Normal file
1
test/pdfs/xfa_bug1721600.pdf.link
Normal file
@ -0,0 +1 @@
|
||||
https://bugzilla.mozilla.org/attachment.cgi?id=9232367
|
@ -952,6 +952,15 @@
|
||||
"enableXfa": true,
|
||||
"type": "eq"
|
||||
},
|
||||
{ "id": "xfa_bug1721600",
|
||||
"file": "pdfs/xfa_bug1721600.pdf",
|
||||
"md5": "5f514f476169eeb7254da380a8db495a",
|
||||
"link": true,
|
||||
"rounds": 1,
|
||||
"lastPage": 1,
|
||||
"enableXfa": true,
|
||||
"type": "eq"
|
||||
},
|
||||
{ "id": "xfa_bug1720182",
|
||||
"file": "pdfs/xfa_bug1720182.pdf",
|
||||
"md5": "1351f816f0509fe750ca61ef2bd40872",
|
||||
|
Loading…
Reference in New Issue
Block a user