Socket
Socket
Sign inDemoInstall

htmljs-parser

Package Overview
Dependencies
Maintainers
1
Versions
109
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

htmljs-parser - npm Package Compare versions

Comparing version 1.0.1 to 1.0.2

59

index.js

@@ -50,3 +50,3 @@

var attributes;
var elementArguments;
var elementArgument;
var tagPos;

@@ -85,3 +85,3 @@ var placeholderPos;

_notifyOpenTag(tagName, attributes, elementArguments, false /* not selfClosed */);
_notifyOpenTag(tagName, attributes, elementArgument, false /* not selfClosed */);

@@ -104,3 +104,3 @@ // Did the parser stay in the same state after

function _afterSelfClosingTag() {
_notifyOpenTag(tagName, attributes, elementArguments, true /* selfClosed */);
_notifyOpenTag(tagName, attributes, elementArgument, true /* selfClosed */);
_notifyCloseTag(tagName, true /* selfClosed */);

@@ -292,25 +292,30 @@ parser.enterHtmlContentState();

var attributeArguments;
var currentAttributeForAgument;
var ignoreArgument;
function _checkForArguments(ch, code) {
function _checkForArgument(ch, code) {
if (code === CODE_LEFT_PARANTHESIS) {
if (attributes === EMPTY_ATTRIBUTES) {
// no attributes so arguments are for element
if (elementArguments == null) {
elementArguments = [];
if ((ignoreArgument = (elementArgument != null))) {
_notifyError(tagPos,
'ILLEGAL_ELEMENT_ARGUMENT',
'Element can only have one argument.');
} else {
elementArgument = ch;
}
elementArguments.push(ch);
parser.enterState(STATE_ELEMENT_ARGUMENTS);
} else {
// arguments are for attribute
var attr = attributes[attributes.length - 1];
currentAttributeForAgument = attributes[attributes.length - 1];
attributeArguments =
attr.arguments ||
(attr.arguments = []);
if ((ignoreArgument = (currentAttributeForAgument.arguments != null))) {
_notifyError(tagPos,
'ILLEGAL_ATTRIBUTE_ARGUMENT',
'Attribute can only have one argument.');
} else {
currentAttributeForAgument.arguments = ch;
}
attributeArguments.push(ch);
parser.enterState(STATE_ATTRIBUTE_ARGUMENTS);

@@ -460,3 +465,3 @@ }

tagName = '';
elementArguments = undefined;
elementArgument = undefined;
withinTag = true;

@@ -540,3 +545,3 @@ },

}
} else if (_checkForArguments(ch, code)) {
} else if (_checkForArgument(ch, code)) {
// encountered something like:

@@ -621,3 +626,3 @@ // <for(var i = 0; i < len; i++)>

// ignore whitespace within element...
} else if (_checkForArguments(ch, code)) {
} else if (_checkForArgument(ch, code)) {
// encountered something like:

@@ -664,3 +669,3 @@ // <for (var i = 0; i < len; i++)>

}
} else if (_checkForArguments(ch, code)) {
} else if (_checkForArgument(ch, code)) {
// Found something like:

@@ -775,7 +780,11 @@ // <div if(a === b)>

char: function(ch, code) {
elementArguments[elementArguments.length - 1] += ch;
if (!ignoreArgument) {
elementArgument += ch;
}
},
string: function(str) {
elementArguments[elementArguments.length - 1] += str;
if (!ignoreArgument) {
elementArgument += str;
}
},

@@ -800,7 +809,11 @@

char: function(ch, code) {
attributeArguments[attributeArguments.length - 1] += ch;
if (!ignoreArgument) {
currentAttributeForAgument.arguments += ch;
}
},
string: function(str) {
attributeArguments[attributeArguments.length - 1] += str;
if (!ignoreArgument) {
currentAttributeForAgument.arguments += str;
}
},

@@ -807,0 +820,0 @@

var CODE_NEWLINE = 10;
function _removeDelimitersFromArguments(args) {
var i = args.length;
while(--i >= 0) {
var arg = args[i];
args[i] = arg.substring(1, arg.length - 1);
}
function _removeDelimitersFromArgument(arg) {
return arg.substring(1, arg.length - 1);
}

@@ -59,3 +55,3 @@

if (elementArguments) {
_removeDelimitersFromArguments(elementArguments);
elementArguments = _removeDelimitersFromArgument(elementArguments);
}

@@ -74,3 +70,3 @@

if (attr.arguments) {
_removeDelimitersFromArguments(attr.arguments);
attr.arguments = _removeDelimitersFromArgument(attr.arguments);
}

@@ -77,0 +73,0 @@

@@ -36,3 +36,3 @@ {

},
"version": "1.0.1"
"version": "1.0.2"
}

@@ -250,5 +250,3 @@ htmljs-parser

name: 'for',
arguments: [
'var i = 0; i < 10; i++'
],
arguments: 'var i = 0; i < 10; i++',
attributes: []

@@ -275,5 +273,3 @@ }

name: 'if',
arguments: [
'x > y'
]
arguments: 'x > y'
}

@@ -581,2 +577,14 @@ ]

Possible errors:
- `ILLEGAL_ELEMENT_ARGUMENT`: Element can only have one argument
- `ILLEGAL_ATTRIBUTE_ARGUMENT`: Attribute can only have one argument
- `MALFORMED_OPEN_TAG`: EOF reached while parsing open tag
- `MALFORMED_CLOSE_TAG`: EOF reached while parsing closing element
- `MALFORMED_CDATA`: EOF reached while parsing CDATA
- `MALFORMED_PLACEHOLDER`: EOF reached while parsing placeholder
- `MALFORMED_DTD`: EOF reached while parsing DTD
- `MALFORMED_DECLARATION`: EOF reached while parsing declaration
- `MALFORMED_COMMENT`: EOF reached while parsing comment
**EXAMPLE:**

@@ -583,0 +591,0 @@

@@ -1168,5 +1168,3 @@ var chai = require('chai');

name: 'for',
arguments: [
'x in y'
],
arguments: 'x in y',
attributes: []

@@ -1184,5 +1182,3 @@ }

name: 'for',
arguments: [
'x in y'
],
arguments: 'x in y',
attributes: []

@@ -1200,5 +1196,3 @@ }

name: 'for',
arguments: [
'x in ["Hello "+(name)+"!", "(World)"]'
],
arguments: 'x in ["Hello "+(name)+"!", "(World)"]',
attributes: []

@@ -1219,5 +1213,3 @@ }

name: 'if',
arguments: [
'x > y'
]
arguments: 'x > y'
}

@@ -1239,5 +1231,3 @@ ]

name: 'if',
arguments: [
'x > y'
]
arguments: 'x > y'
}

@@ -1256,11 +1246,7 @@ ]

name: 'for',
arguments: [
'var i = 0; i < 10; i++'
],
arguments: 'var i = 0; i < 10; i++',
attributes: [
{
name: 'if',
arguments: [
'x > y'
]
arguments: 'x > y'
}

@@ -1271,2 +1257,48 @@ ]

});
it('should allow only one argument per tag', function() {
parse([
'<for(var i = 0; i < 10; i++) (nonsense!)>'
], [
{
code: 'ILLEGAL_ELEMENT_ARGUMENT',
endPos: 30,
lineNumber: 1,
message: 'Element can only have one argument.',
startPos: 0,
type: 'error'
},
{
type: 'opentag',
name: 'for',
arguments: 'var i = 0; i < 10; i++',
attributes: []
}
]);
});
it('should allow only one argument per attribute', function() {
parse([
'<div for(var i = 0; i < 10; i++) (nonsense!)>'
], [
{
code: 'ILLEGAL_ATTRIBUTE_ARGUMENT',
lineNumber: 1,
message: 'Attribute can only have one argument.',
startPos: 0,
endPos: 34,
type: 'error'
},
{
type: 'opentag',
name: 'div',
attributes: [
{
name: 'for',
arguments: 'var i = 0; i < 10; i++'
}
]
}
]);
});
});

@@ -1273,0 +1305,0 @@

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