plist 3.0.3 → 3.0.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.github/workflows/ci.yml +24 -0
- package/History.md +17 -0
- package/README.md +5 -5
- package/dist/plist-build.js +4130 -1651
- package/dist/plist-parse.js +4153 -4135
- package/dist/plist.js +8768 -6271
- package/lib/build.js +3 -0
- package/lib/parse.js +14 -2
- package/lib/xmldom/dom-parser.js +253 -0
- package/lib/xmldom/dom.js +1283 -0
- package/lib/xmldom/entities.js +243 -0
- package/lib/xmldom/sax.js +642 -0
- package/package.json +7 -8
package/lib/build.js
CHANGED
package/lib/parse.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
* Module dependencies.
|
|
3
3
|
*/
|
|
4
4
|
|
|
5
|
-
var DOMParser = require('xmldom').DOMParser;
|
|
5
|
+
var DOMParser = require('./xmldom/dom-parser').DOMParser;
|
|
6
6
|
|
|
7
7
|
/**
|
|
8
8
|
* Module exports.
|
|
@@ -129,8 +129,9 @@ function parsePlistXML (node) {
|
|
|
129
129
|
counter += 1;
|
|
130
130
|
}
|
|
131
131
|
if (counter % 2 === 1) {
|
|
132
|
-
|
|
132
|
+
new_obj[key] = '';
|
|
133
133
|
}
|
|
134
|
+
|
|
134
135
|
return new_obj;
|
|
135
136
|
|
|
136
137
|
} else if (node.nodeName === 'array') {
|
|
@@ -153,6 +154,12 @@ function parsePlistXML (node) {
|
|
|
153
154
|
if (isEmptyNode(node)) {
|
|
154
155
|
return '';
|
|
155
156
|
}
|
|
157
|
+
|
|
158
|
+
invariant(
|
|
159
|
+
node.childNodes[0].nodeValue !== '__proto__',
|
|
160
|
+
'__proto__ keys can lead to prototype pollution. More details on CVE-2022-22912'
|
|
161
|
+
);
|
|
162
|
+
|
|
156
163
|
return node.childNodes[0].nodeValue;
|
|
157
164
|
} else if (node.nodeName === 'string') {
|
|
158
165
|
res = '';
|
|
@@ -206,10 +213,15 @@ function parsePlistXML (node) {
|
|
|
206
213
|
)
|
|
207
214
|
return new Date(node.childNodes[0].nodeValue);
|
|
208
215
|
|
|
216
|
+
} else if (node.nodeName === 'null') {
|
|
217
|
+
return null;
|
|
218
|
+
|
|
209
219
|
} else if (node.nodeName === 'true') {
|
|
210
220
|
return true;
|
|
211
221
|
|
|
212
222
|
} else if (node.nodeName === 'false') {
|
|
213
223
|
return false;
|
|
224
|
+
} else {
|
|
225
|
+
throw new Error('Invalid PLIST tag ' + node.nodeName);
|
|
214
226
|
}
|
|
215
227
|
}
|
|
@@ -0,0 +1,253 @@
|
|
|
1
|
+
function DOMParser(options){
|
|
2
|
+
this.options = options ||{locator:{}};
|
|
3
|
+
}
|
|
4
|
+
|
|
5
|
+
DOMParser.prototype.parseFromString = function(source,mimeType){
|
|
6
|
+
var options = this.options;
|
|
7
|
+
var sax = new XMLReader();
|
|
8
|
+
var domBuilder = options.domBuilder || new DOMHandler();//contentHandler and LexicalHandler
|
|
9
|
+
var errorHandler = options.errorHandler;
|
|
10
|
+
var locator = options.locator;
|
|
11
|
+
var defaultNSMap = options.xmlns||{};
|
|
12
|
+
var isHTML = /\/x?html?$/.test(mimeType);//mimeType.toLowerCase().indexOf('html') > -1;
|
|
13
|
+
var entityMap = isHTML?htmlEntity.entityMap:{'lt':'<','gt':'>','amp':'&','quot':'"','apos':"'"};
|
|
14
|
+
if(locator){
|
|
15
|
+
domBuilder.setDocumentLocator(locator)
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
sax.errorHandler = buildErrorHandler(errorHandler,domBuilder,locator);
|
|
19
|
+
sax.domBuilder = options.domBuilder || domBuilder;
|
|
20
|
+
if(isHTML){
|
|
21
|
+
defaultNSMap['']= 'http://www.w3.org/1999/xhtml';
|
|
22
|
+
}
|
|
23
|
+
defaultNSMap.xml = defaultNSMap.xml || 'http://www.w3.org/XML/1998/namespace';
|
|
24
|
+
if(source && typeof source === 'string'){
|
|
25
|
+
sax.parse(source,defaultNSMap,entityMap);
|
|
26
|
+
}else{
|
|
27
|
+
sax.errorHandler.error("invalid doc source");
|
|
28
|
+
}
|
|
29
|
+
return domBuilder.doc;
|
|
30
|
+
}
|
|
31
|
+
function buildErrorHandler(errorImpl,domBuilder,locator){
|
|
32
|
+
if(!errorImpl){
|
|
33
|
+
if(domBuilder instanceof DOMHandler){
|
|
34
|
+
return domBuilder;
|
|
35
|
+
}
|
|
36
|
+
errorImpl = domBuilder ;
|
|
37
|
+
}
|
|
38
|
+
var errorHandler = {}
|
|
39
|
+
var isCallback = errorImpl instanceof Function;
|
|
40
|
+
locator = locator||{}
|
|
41
|
+
function build(key){
|
|
42
|
+
var fn = errorImpl[key];
|
|
43
|
+
if(!fn && isCallback){
|
|
44
|
+
fn = errorImpl.length == 2?function(msg){errorImpl(key,msg)}:errorImpl;
|
|
45
|
+
}
|
|
46
|
+
errorHandler[key] = fn && function(msg){
|
|
47
|
+
fn('[xmldom '+key+']\t'+msg+_locator(locator));
|
|
48
|
+
}||function(){};
|
|
49
|
+
}
|
|
50
|
+
build('warning');
|
|
51
|
+
build('error');
|
|
52
|
+
build('fatalError');
|
|
53
|
+
return errorHandler;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
//console.log('#\n\n\n\n\n\n\n####')
|
|
57
|
+
/**
|
|
58
|
+
* +ContentHandler+ErrorHandler
|
|
59
|
+
* +LexicalHandler+EntityResolver2
|
|
60
|
+
* -DeclHandler-DTDHandler
|
|
61
|
+
*
|
|
62
|
+
* DefaultHandler:EntityResolver, DTDHandler, ContentHandler, ErrorHandler
|
|
63
|
+
* DefaultHandler2:DefaultHandler,LexicalHandler, DeclHandler, EntityResolver2
|
|
64
|
+
* @link http://www.saxproject.org/apidoc/org/xml/sax/helpers/DefaultHandler.html
|
|
65
|
+
*/
|
|
66
|
+
function DOMHandler() {
|
|
67
|
+
this.cdata = false;
|
|
68
|
+
}
|
|
69
|
+
function position(locator,node){
|
|
70
|
+
node.lineNumber = locator.lineNumber;
|
|
71
|
+
node.columnNumber = locator.columnNumber;
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* @see org.xml.sax.ContentHandler#startDocument
|
|
75
|
+
* @link http://www.saxproject.org/apidoc/org/xml/sax/ContentHandler.html
|
|
76
|
+
*/
|
|
77
|
+
DOMHandler.prototype = {
|
|
78
|
+
startDocument : function() {
|
|
79
|
+
this.doc = new DOMImplementation().createDocument(null, null, null);
|
|
80
|
+
if (this.locator) {
|
|
81
|
+
this.doc.documentURI = this.locator.systemId;
|
|
82
|
+
}
|
|
83
|
+
},
|
|
84
|
+
startElement:function(namespaceURI, localName, qName, attrs) {
|
|
85
|
+
var doc = this.doc;
|
|
86
|
+
var el = doc.createElementNS(namespaceURI, qName||localName);
|
|
87
|
+
var len = attrs.length;
|
|
88
|
+
appendElement(this, el);
|
|
89
|
+
this.currentElement = el;
|
|
90
|
+
|
|
91
|
+
this.locator && position(this.locator,el)
|
|
92
|
+
for (var i = 0 ; i < len; i++) {
|
|
93
|
+
var namespaceURI = attrs.getURI(i);
|
|
94
|
+
var value = attrs.getValue(i);
|
|
95
|
+
var qName = attrs.getQName(i);
|
|
96
|
+
var attr = doc.createAttributeNS(namespaceURI, qName);
|
|
97
|
+
this.locator &&position(attrs.getLocator(i),attr);
|
|
98
|
+
attr.value = attr.nodeValue = value;
|
|
99
|
+
el.setAttributeNode(attr)
|
|
100
|
+
}
|
|
101
|
+
},
|
|
102
|
+
endElement:function(namespaceURI, localName, qName) {
|
|
103
|
+
var current = this.currentElement
|
|
104
|
+
var tagName = current.tagName;
|
|
105
|
+
this.currentElement = current.parentNode;
|
|
106
|
+
},
|
|
107
|
+
startPrefixMapping:function(prefix, uri) {
|
|
108
|
+
},
|
|
109
|
+
endPrefixMapping:function(prefix) {
|
|
110
|
+
},
|
|
111
|
+
processingInstruction:function(target, data) {
|
|
112
|
+
var ins = this.doc.createProcessingInstruction(target, data);
|
|
113
|
+
this.locator && position(this.locator,ins)
|
|
114
|
+
appendElement(this, ins);
|
|
115
|
+
},
|
|
116
|
+
ignorableWhitespace:function(ch, start, length) {
|
|
117
|
+
},
|
|
118
|
+
characters:function(chars, start, length) {
|
|
119
|
+
chars = _toString.apply(this,arguments)
|
|
120
|
+
//console.log(chars)
|
|
121
|
+
if(chars){
|
|
122
|
+
if (this.cdata) {
|
|
123
|
+
var charNode = this.doc.createCDATASection(chars);
|
|
124
|
+
} else {
|
|
125
|
+
var charNode = this.doc.createTextNode(chars);
|
|
126
|
+
}
|
|
127
|
+
if(this.currentElement){
|
|
128
|
+
this.currentElement.appendChild(charNode);
|
|
129
|
+
}else if(/^\s*$/.test(chars)){
|
|
130
|
+
this.doc.appendChild(charNode);
|
|
131
|
+
//process xml
|
|
132
|
+
}
|
|
133
|
+
this.locator && position(this.locator,charNode)
|
|
134
|
+
}
|
|
135
|
+
},
|
|
136
|
+
skippedEntity:function(name) {
|
|
137
|
+
},
|
|
138
|
+
endDocument:function() {
|
|
139
|
+
this.doc.normalize();
|
|
140
|
+
},
|
|
141
|
+
setDocumentLocator:function (locator) {
|
|
142
|
+
if(this.locator = locator){// && !('lineNumber' in locator)){
|
|
143
|
+
locator.lineNumber = 0;
|
|
144
|
+
}
|
|
145
|
+
},
|
|
146
|
+
//LexicalHandler
|
|
147
|
+
comment:function(chars, start, length) {
|
|
148
|
+
chars = _toString.apply(this,arguments)
|
|
149
|
+
var comm = this.doc.createComment(chars);
|
|
150
|
+
this.locator && position(this.locator,comm)
|
|
151
|
+
appendElement(this, comm);
|
|
152
|
+
},
|
|
153
|
+
|
|
154
|
+
startCDATA:function() {
|
|
155
|
+
//used in characters() methods
|
|
156
|
+
this.cdata = true;
|
|
157
|
+
},
|
|
158
|
+
endCDATA:function() {
|
|
159
|
+
this.cdata = false;
|
|
160
|
+
},
|
|
161
|
+
|
|
162
|
+
startDTD:function(name, publicId, systemId) {
|
|
163
|
+
var impl = this.doc.implementation;
|
|
164
|
+
if (impl && impl.createDocumentType) {
|
|
165
|
+
var dt = impl.createDocumentType(name, publicId, systemId);
|
|
166
|
+
this.locator && position(this.locator,dt)
|
|
167
|
+
appendElement(this, dt);
|
|
168
|
+
}
|
|
169
|
+
},
|
|
170
|
+
/**
|
|
171
|
+
* @see org.xml.sax.ErrorHandler
|
|
172
|
+
* @link http://www.saxproject.org/apidoc/org/xml/sax/ErrorHandler.html
|
|
173
|
+
*/
|
|
174
|
+
warning:function(error) {
|
|
175
|
+
console.warn('[xmldom warning]\t'+error,_locator(this.locator));
|
|
176
|
+
},
|
|
177
|
+
error:function(error) {
|
|
178
|
+
console.error('[xmldom error]\t'+error,_locator(this.locator));
|
|
179
|
+
},
|
|
180
|
+
fatalError:function(error) {
|
|
181
|
+
throw new ParseError(error, this.locator);
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
function _locator(l){
|
|
185
|
+
if(l){
|
|
186
|
+
return '\n@'+(l.systemId ||'')+'#[line:'+l.lineNumber+',col:'+l.columnNumber+']'
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
function _toString(chars,start,length){
|
|
190
|
+
if(typeof chars == 'string'){
|
|
191
|
+
return chars.substr(start,length)
|
|
192
|
+
}else{//java sax connect width xmldom on rhino(what about: "? && !(chars instanceof String)")
|
|
193
|
+
if(chars.length >= start+length || start){
|
|
194
|
+
return new java.lang.String(chars,start,length)+'';
|
|
195
|
+
}
|
|
196
|
+
return chars;
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
/*
|
|
201
|
+
* @link http://www.saxproject.org/apidoc/org/xml/sax/ext/LexicalHandler.html
|
|
202
|
+
* used method of org.xml.sax.ext.LexicalHandler:
|
|
203
|
+
* #comment(chars, start, length)
|
|
204
|
+
* #startCDATA()
|
|
205
|
+
* #endCDATA()
|
|
206
|
+
* #startDTD(name, publicId, systemId)
|
|
207
|
+
*
|
|
208
|
+
*
|
|
209
|
+
* IGNORED method of org.xml.sax.ext.LexicalHandler:
|
|
210
|
+
* #endDTD()
|
|
211
|
+
* #startEntity(name)
|
|
212
|
+
* #endEntity(name)
|
|
213
|
+
*
|
|
214
|
+
*
|
|
215
|
+
* @link http://www.saxproject.org/apidoc/org/xml/sax/ext/DeclHandler.html
|
|
216
|
+
* IGNORED method of org.xml.sax.ext.DeclHandler
|
|
217
|
+
* #attributeDecl(eName, aName, type, mode, value)
|
|
218
|
+
* #elementDecl(name, model)
|
|
219
|
+
* #externalEntityDecl(name, publicId, systemId)
|
|
220
|
+
* #internalEntityDecl(name, value)
|
|
221
|
+
* @link http://www.saxproject.org/apidoc/org/xml/sax/ext/EntityResolver2.html
|
|
222
|
+
* IGNORED method of org.xml.sax.EntityResolver2
|
|
223
|
+
* #resolveEntity(String name,String publicId,String baseURI,String systemId)
|
|
224
|
+
* #resolveEntity(publicId, systemId)
|
|
225
|
+
* #getExternalSubset(name, baseURI)
|
|
226
|
+
* @link http://www.saxproject.org/apidoc/org/xml/sax/DTDHandler.html
|
|
227
|
+
* IGNORED method of org.xml.sax.DTDHandler
|
|
228
|
+
* #notationDecl(name, publicId, systemId) {};
|
|
229
|
+
* #unparsedEntityDecl(name, publicId, systemId, notationName) {};
|
|
230
|
+
*/
|
|
231
|
+
"endDTD,startEntity,endEntity,attributeDecl,elementDecl,externalEntityDecl,internalEntityDecl,resolveEntity,getExternalSubset,notationDecl,unparsedEntityDecl".replace(/\w+/g,function(key){
|
|
232
|
+
DOMHandler.prototype[key] = function(){return null}
|
|
233
|
+
})
|
|
234
|
+
|
|
235
|
+
/* Private static helpers treated below as private instance methods, so don't need to add these to the public API; we might use a Relator to also get rid of non-standard public properties */
|
|
236
|
+
function appendElement (hander,node) {
|
|
237
|
+
if (!hander.currentElement) {
|
|
238
|
+
hander.doc.appendChild(node);
|
|
239
|
+
} else {
|
|
240
|
+
hander.currentElement.appendChild(node);
|
|
241
|
+
}
|
|
242
|
+
}//appendChild and setAttributeNS are preformance key
|
|
243
|
+
|
|
244
|
+
//if(typeof require == 'function'){
|
|
245
|
+
var htmlEntity = require('./entities');
|
|
246
|
+
var sax = require('./sax');
|
|
247
|
+
var XMLReader = sax.XMLReader;
|
|
248
|
+
var ParseError = sax.ParseError;
|
|
249
|
+
var DOMImplementation = exports.DOMImplementation = require('./dom').DOMImplementation;
|
|
250
|
+
exports.XMLSerializer = require('./dom').XMLSerializer ;
|
|
251
|
+
exports.DOMParser = DOMParser;
|
|
252
|
+
exports.__DOMHandler = DOMHandler;
|
|
253
|
+
//}
|