Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

encode entity "greater-than" (>) in text node #199

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
86 changes: 43 additions & 43 deletions dom.js
Original file line number Diff line number Diff line change
Expand Up @@ -98,14 +98,14 @@ NodeList.prototype = {
* The number of nodes in the list. The range of valid child node indices is 0 to length-1 inclusive.
* @standard level1
*/
length:0,
length:0,
/**
* Returns the indexth item in the collection. If index is greater than or equal to the number of nodes in the list, this returns null.
* @standard level1
* @param index unsigned long
* @param index unsigned long
* Index into the collection.
* @return Node
* The node at the indexth position in the NodeList, or null if that is not a valid index.
* The node at the indexth position in the NodeList, or null if that is not a valid index.
*/
item: function(index) {
return this[index] || null;
Expand Down Expand Up @@ -139,10 +139,10 @@ LiveNodeList.prototype.item = function(i){

_extends(LiveNodeList,NodeList);
/**
*
*
* Objects implementing the NamedNodeMap interface are used to represent collections of nodes that can be accessed by name. Note that NamedNodeMap does not inherit from NodeList; NamedNodeMaps are not maintained in any particular order. Objects contained in an object implementing NamedNodeMap may also be accessed by an ordinal index, but this is simply to allow convenient enumeration of the contents of a NamedNodeMap, and does not imply that the DOM specifies an order to these Nodes.
* NamedNodeMap objects in the DOM are live.
* used for attributes or DocumentType entities
* used for attributes or DocumentType entities
*/
function NamedNodeMap() {
};
Expand Down Expand Up @@ -231,10 +231,10 @@ NamedNodeMap.prototype = {
var attr = this.getNamedItem(key);
_removeNamedNode(this._ownerElement,this,attr);
return attr;


},// raises: NOT_FOUND_ERR,NO_MODIFICATION_ALLOWED_ERR

//for level2
removeNamedItemNS:function(namespaceURI,localName){
var attr = this.getNamedItemNS(namespaceURI,localName);
Expand Down Expand Up @@ -297,7 +297,7 @@ DOMImplementation.prototype = {
node.systemId = systemId;
// Introduced in DOM Level 2:
//readonly attribute DOMString internalSubset;

//TODO:..
// readonly attribute NamedNodeMap entities;
// readonly attribute NamedNodeMap notations;
Expand Down Expand Up @@ -327,10 +327,10 @@ Node.prototype = {
prefix : null,
localName : null,
// Modified in DOM Level 2:
insertBefore:function(newChild, refChild){//raises
insertBefore:function(newChild, refChild){//raises
return _insertBefore(this,newChild,refChild);
},
replaceChild:function(newChild, oldChild){//raises
replaceChild:function(newChild, oldChild){//raises
this.insertBefore(newChild,oldChild);
if(oldChild){
this.removeChild(oldChild);
Expand Down Expand Up @@ -479,7 +479,7 @@ function _onUpdateChild(doc,el,newChild){
/**
* attributes;
* children;
*
*
* writeable properties:
* nodeValue,Attr:value,CharacterData:data
* prefix
Expand Down Expand Up @@ -521,8 +521,8 @@ function _insertBefore(parentNode,newChild,nextChild){

newFirst.previousSibling = pre;
newLast.nextSibling = nextChild;


if(pre){
pre.nextSibling = newFirst;
}else{
Expand Down Expand Up @@ -571,8 +571,8 @@ Document.prototype = {
doctype : null,
documentElement : null,
_inc : 1,
insertBefore : function(newChild, refChild){//raises

insertBefore : function(newChild, refChild){//raises
if(newChild.nodeType == DOCUMENT_FRAGMENT_NODE){
var child = newChild.firstChild;
while(child){
Expand All @@ -585,7 +585,7 @@ Document.prototype = {
if(this.documentElement == null && newChild.nodeType == ELEMENT_NODE){
this.documentElement = newChild;
}

return _insertBefore(this,newChild,refChild),(newChild.ownerDocument = this),newChild;
},
removeChild : function(oldChild){
Expand All @@ -611,7 +611,7 @@ Document.prototype = {
})
return rtv;
},

//document factory method:
createElement : function(tagName){
var node = new Element();
Expand Down Expand Up @@ -735,7 +735,7 @@ Element.prototype = {
var attr = this.getAttributeNode(name)
attr && this.removeAttributeNode(attr);
},

//four real opeartion method
appendChild:function(newChild){
if(newChild.nodeType === DOCUMENT_FRAGMENT_NODE){
Expand All @@ -759,7 +759,7 @@ Element.prototype = {
var old = this.getAttributeNodeNS(namespaceURI, localName);
old && this.removeAttributeNode(old);
},

hasAttributeNS : function(namespaceURI, localName){
return this.getAttributeNodeNS(namespaceURI, localName)!=null;
},
Expand All @@ -775,7 +775,7 @@ Element.prototype = {
getAttributeNodeNS : function(namespaceURI, localName){
return this.attributes.getNamedItemNS(namespaceURI, localName);
},

getElementsByTagName : function(tagName){
return new LiveNodeList(this,function(base){
var ls = [];
Expand All @@ -796,7 +796,7 @@ Element.prototype = {
}
});
return ls;

});
}
};
Expand Down Expand Up @@ -825,7 +825,7 @@ CharacterData.prototype = {
},
insertData: function(offset,text) {
this.replaceData(offset,0,text);

},
appendChild:function(newChild){
throw new Error(ExceptionMessage[HIERARCHY_REQUEST_ERR])
Expand Down Expand Up @@ -919,7 +919,7 @@ function nodeSerializeToString(isHtml,nodeFilter){
var refNode = this.nodeType == 9 && this.documentElement || this;
var prefix = refNode.prefix;
var uri = refNode.namespaceURI;

if(uri && prefix == null){
//console.log(prefix)
var prefix = refNode.lookupPrefix(uri);
Expand All @@ -941,12 +941,12 @@ function needNamespaceDefine(node,isHTML, visibleNamespaces) {
if (!prefix && !uri){
return false;
}
if (prefix === "xml" && uri === "http://www.w3.org/XML/1998/namespace"
if (prefix === "xml" && uri === "http://www.w3.org/XML/1998/namespace"
|| uri == 'http://www.w3.org/2000/xmlns/'){
return false;
}
var i = visibleNamespaces.length

var i = visibleNamespaces.length
//console.log('@@@@',node.tagName,prefix,uri,visibleNamespaces)
while (i--) {
var ns = visibleNamespaces[i];
Expand Down Expand Up @@ -985,12 +985,12 @@ function serializeToString(node,buf,isHTML,nodeFilter,visibleNamespaces){
var len = attrs.length;
var child = node.firstChild;
var nodeName = node.tagName;
isHTML = (htmlns === node.namespaceURI) ||isHTML

isHTML = (htmlns === node.namespaceURI) ||isHTML
buf.push('<',nodeName);



for(var i=0;i<len;i++){
// add namespaces for attributes
var attr = attrs.item(i);
Expand All @@ -1002,24 +1002,24 @@ function serializeToString(node,buf,isHTML,nodeFilter,visibleNamespaces){
}
for(var i=0;i<len;i++){
var attr = attrs.item(i);
if (needNamespaceDefine(attr,isHTML, visibleNamespaces)) {
var prefix = attr.prefix||'';
var uri = attr.namespaceURI;
if (needNamespaceDefine(attr, isHTML, visibleNamespaces)) {
var prefix = attr.prefix || '';
var uri = (!!node.namespaceURI) ? node.namespaceURI : './lite';
var ns = prefix ? ' xmlns:' + prefix : " xmlns";
buf.push(ns, '="' , uri , '"');
visibleNamespaces.push({ prefix: prefix, namespace:uri });
visibleNamespaces.push({ prefix: prefix, namespace: uri });
}
serializeToString(attr,buf,isHTML,nodeFilter,visibleNamespaces);
}
// add namespace for current node
// add namespace for current node
if (needNamespaceDefine(node,isHTML, visibleNamespaces)) {
var prefix = node.prefix||'';
var uri = node.namespaceURI;
var prefix = node.prefix || '';
var uri = (!!node.namespaceURI) ? node.namespaceURI : './lite';
var ns = prefix ? ' xmlns:' + prefix : " xmlns";
buf.push(ns, '="' , uri , '"');
visibleNamespaces.push({ prefix: prefix, namespace:uri });
visibleNamespaces.push({ prefix: prefix, namespace: uri });
}

if(child || isHTML && !/^(?:meta|link|img|br|hr|input)$/i.test(nodeName)){
buf.push('>');
//if is cdata child node
Expand Down Expand Up @@ -1057,7 +1057,7 @@ function serializeToString(node,buf,isHTML,nodeFilter,visibleNamespaces){
case ATTRIBUTE_NODE:
return buf.push(' ',node.name,'="',node.value.replace(/[<&"]/g,_xmlEncoder),'"');
case TEXT_NODE:
return buf.push(node.data.replace(/[<&]/g,_xmlEncoder));
return buf.push(node.data.replace(/[<>&]/g,_xmlEncoder));
case CDATA_SECTION_NODE:
return buf.push( '<![CDATA[',node.data,']]>');
case COMMENT_NODE:
Expand Down Expand Up @@ -1212,7 +1212,7 @@ try{
}
}
})

function getTextContent(node){
switch(node.nodeType){
case ELEMENT_NODE:
Expand Down
22 changes: 11 additions & 11 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
{
"name": "xmldom",
"version": "0.1.27",
"version": "0.1.28",
"description": "A W3C Standard XML DOM(Level2 CORE) implementation and parser(DOMParser/XMLSerializer).",
"keywords": ["w3c","dom","xml","parser","javascript","DOMParser","XMLSerializer"],
"keywords": ["w3c", "dom", "xml", "parser", "javascript", "DOMParser", "XMLSerializer"],
"author": "jindw <[email protected]> (http://www.xidea.org)",
"homepage": "https://github.com/jindw/xmldom",
"repository": {"type": "git","url": "git://github.com/jindw/xmldom.git"},
"repository": { "type": "git", "url": "git://github.com/jindw/xmldom.git" },
"main": "./dom-parser.js",
"scripts" : { "test": "proof platform win32 && proof test */*/*.t.js || t/test" },
"engines": {"node": ">=0.1"},
"scripts": { "test": "proof platform win32 && proof test */*/*.t.js || t/test" },
"engines": { "node": ">=0.1" },
"dependencies": {},
"devDependencies": { "proof": "0.0.28" },
"maintainers": [{"name": "jindw","email": "[email protected]","url": "http://www.xidea.org"}],
"maintainers": [{ "name": "jindw", "email": "[email protected]", "url": "http://www.xidea.org" }],
"contributors": [
{"name" : "Yaron Naveh","email" : "[email protected]","web" : "http://webservices20.blogspot.com/"},
{"name" : "Harutyun Amirjanyan","email" : "[email protected]","web" : "https://github.com/nightwing"},
{"name" : "Alan Gutierrez","email" : "[email protected]","web" : "http://www.prettyrobots.com/"}
{ "name": "Yaron Naveh", "email": "[email protected]", "web": "http://webservices20.blogspot.com/" },
{ "name": "Harutyun Amirjanyan", "email": "[email protected]", "web": "https://github.com/nightwing" },
{ "name": "Alan Gutierrez", "email": "[email protected]", "web": "http://www.prettyrobots.com/" }
],
"bugs": {"email": "[email protected]","url": "http://github.com/jindw/xmldom/issues"},
"bugs": { "email": "[email protected]", "url": "http://github.com/jindw/xmldom/issues" },
"license": "(LGPL-2.0 or MIT)"
}
}
2 changes: 1 addition & 1 deletion test/dom/serializer.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ wows.describe('XML Serializer').addBatch({
'text node containing "]]>"': function() {
var doc = new DOMParser().parseFromString('<test/>', 'text/xml');
doc.documentElement.appendChild(doc.createTextNode('hello ]]> there'));
console.assert(doc.documentElement.firstChild.toString() == 'hello ]]> there',doc.documentElement.firstChild.toString());
console.assert(doc.documentElement.firstChild.toString() == 'hello ]]&gt; there',doc.documentElement.firstChild.toString());
},
'<script> element with no children': function() {
var doc = new DOMParser({xmlns:{xmlns:'http://www.w3.org/1999/xhtml'}}).parseFromString('<html2><script></script></html2>', 'text/html');
Expand Down