Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

elementtree

Package Overview
Dependencies
Maintainers
1
Versions
8
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

elementtree - npm Package Compare versions

Comparing version 0.1.0 to 0.1.1

51

lib/elementtree.js

@@ -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, '&lt;');
text = text.replace(/>/g, '&gt;');
text = text.replace(/\n/g, '&#xA;');
text = text.replace(/\r/g, '&#xD;');
if (isAttribute) {
text = text.replace(/"/g, '&quot;');
}
}
if (text.indexOf("&") !== -1) {
text = text.replace("&", "&amp;");
}
if (text.indexOf("<") !== -1) {
text = text.replace("<", "&lt;");
}
if (text.indexOf(">") !== -1) {
text = text.replace(">", "&gt;");
}
if (text.indexOf("\"") !== -1) {
text = text.replace("\"", "&quot;");
}
if (text.indexOf("\n") !== -1) {
text = text.replace("\n", "&#10;");
}
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("&", "&amp;");
}
if (text.indexOf("<") !== -1) {
text = text.replace("<", "&lt;");
}
if (text.indexOf(">") !== -1) {
text = text.replace(">", "&gt;");
}
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>&amp;&amp;&amp;&amp;&lt;&gt;\"&#xA;&#xD;</b></a>');
test.finish();
};
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc