elementtree
Advanced tools
Comparing version 0.1.0 to 0.1.1
@@ -347,44 +347,25 @@ /** | ||
/* TODO: benchmark single regex */ | ||
// TODO replace without regex only replaces single instance | ||
function _escape_attrib(text, encoding) { | ||
function _escape(text, encoding, isAttribute) { | ||
if (text) { | ||
text = text.toString(); | ||
text = text.replace(/&/g, '&'); | ||
text = text.replace(/</g, '<'); | ||
text = text.replace(/>/g, '>'); | ||
text = text.replace(/\n/g, '
'); | ||
text = text.replace(/\r/g, '
'); | ||
if (isAttribute) { | ||
text = text.replace(/"/g, '"'); | ||
} | ||
} | ||
if (text.indexOf("&") !== -1) { | ||
text = text.replace("&", "&"); | ||
} | ||
if (text.indexOf("<") !== -1) { | ||
text = text.replace("<", "<"); | ||
} | ||
if (text.indexOf(">") !== -1) { | ||
text = text.replace(">", ">"); | ||
} | ||
if (text.indexOf("\"") !== -1) { | ||
text = text.replace("\"", """); | ||
} | ||
if (text.indexOf("\n") !== -1) { | ||
text = text.replace("\n", " "); | ||
} | ||
return text; | ||
} | ||
/* TODO: benchmark single regex */ | ||
function _escape_attrib(text, encoding) { | ||
return _escape(text, encoding, true); | ||
} | ||
function _escape_cdata(text, encoding) { | ||
if (text) { | ||
text = text.toString(); | ||
} | ||
if (text.indexOf("&") !== -1) { | ||
text = text.replace("&", "&"); | ||
} | ||
if (text.indexOf("<") !== -1) { | ||
text = text.replace("<", "<"); | ||
} | ||
if (text.indexOf(">") !== -1) { | ||
text = text.replace(">", ">"); | ||
} | ||
return text; | ||
return _escape(text, encoding, false); | ||
} | ||
@@ -391,0 +372,0 @@ |
@@ -9,3 +9,3 @@ { | ||
"description": "XML Serialization and Parsing module based on Python's ElementTree.", | ||
"version": "0.1.0", | ||
"version": "0.1.1", | ||
"keywords": [ "xml", "sax", "parser", "seralization", "elementtree" ], | ||
@@ -12,0 +12,0 @@ "homepage": "https://github.com/racker/node-elementtree", |
@@ -6,10 +6,9 @@ node-elementtree | ||
Status | ||
Using the library | ||
==================== | ||
Incomplete. Basics work. Major work ongoing. | ||
Using library | ||
==================== | ||
Supported XPath expressions in find, findall and findtext methods are listed on [http://effbot.org/zone/element-xpath.htm](http://effbot.org/zone/element-xpath.htm). | ||
For the usage refer to the Python ElementTree library documentation - [http://effbot.org/zone/element-index.htm#usage](http://effbot.org/zone/element-index.htm#usage). | ||
Supported XPath expressions in `find`, `findall` and `findtext` methods are listed on [http://effbot.org/zone/element-xpath.htm](http://effbot.org/zone/element-xpath.htm). | ||
License | ||
@@ -24,2 +23,1 @@ ==================== | ||
$ npm install elementtree | ||
@@ -199,1 +199,10 @@ /** | ||
}; | ||
exports['test_escape'] = function(test, assert) { | ||
var a = Element('a'); | ||
var b = SubElement(a, 'b'); | ||
b.text = '&&&&<>"\n\r'; | ||
assert.equal(et.tostring(a, { 'xml_declaration': false }), '<a><b>&&&&<>\"

</b></a>'); | ||
test.finish(); | ||
}; |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
48825
1208
22