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

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.2 to 1.0.3

33

index.js

@@ -309,3 +309,3 @@

if ((ignoreArgument = (currentAttributeForAgument.arguments != null))) {
if ((ignoreArgument = (currentAttributeForAgument.argument != null))) {
_notifyError(tagPos,

@@ -315,3 +315,3 @@ 'ILLEGAL_ATTRIBUTE_ARGUMENT',

} else {
currentAttributeForAgument.arguments = ch;
currentAttributeForAgument.argument = ch;
}

@@ -648,2 +648,3 @@

attribute.expression = '';
attribute.isSimpleLiteral = true;
parser.enterState(STATE_ATTRIBUTE_VALUE);

@@ -710,5 +711,5 @@ } else if (code === CODE_RIGHT_ANGLE_BRACKET) {

string: function(str, staticText) {
if (!staticText) {
attribute.possibleStaticText = false;
string: function(str, isStringLiteral) {
if (!isStringLiteral) {
attribute.isStringLiteral = false;
}

@@ -726,5 +727,6 @@

if ((code === CODE_SINGLE_QUOTE) || (code === CODE_DOUBLE_QUOTE)) {
// The attribute value is possibly static text if the
// The attribute value is possibly a string literal if the
// first character for the value is a single or double quote
attribute.possibleStaticText = (attribute.expression.length === 0);
attribute.isStringLiteral = (attribute.expression.length === 0);
attribute.isSimpleLiteral = false;
_enterExpressionState(ch, code, code, STATE_STRING);

@@ -749,2 +751,3 @@ return;

} else if (nextCode === CODE_ASTERISK) {
attribute.isSimpleLiteral = false;
parser.skip(1);

@@ -760,10 +763,16 @@ return _enterBlockCommentState();

} else if (code === CODE_LEFT_PARANTHESIS) {
attribute.isSimpleLiteral = false;
_enterExpressionState(ch, code, CODE_RIGHT_PARANTHESIS, STATE_DELIMITED_EXPRESSION);
} else if (code === CODE_LEFT_CURLY_BRACE) {
attribute.isSimpleLiteral = false;
_enterExpressionState(ch, code, CODE_RIGHT_CURLY_BRACE, STATE_DELIMITED_EXPRESSION);
} else if (code === CODE_LEFT_SQUARE_BRACKET) {
attribute.isSimpleLiteral = false;
_enterExpressionState(ch, code, CODE_RIGHT_SQUARE_BRACKET, STATE_DELIMITED_EXPRESSION);
}
attribute.possibleStaticText = false;
// If we got here then we are parsing characters that were
// not within a quoted string so our value can't possibly be
// a string literal
attribute.isStringLiteral = false;

@@ -808,3 +817,3 @@ attribute.expression += ch;

if (!ignoreArgument) {
currentAttributeForAgument.arguments += ch;
currentAttributeForAgument.argument += ch;
}

@@ -815,3 +824,3 @@ },

if (!ignoreArgument) {
currentAttributeForAgument.arguments += str;
currentAttributeForAgument.argument += str;
}

@@ -995,3 +1004,3 @@ },

expressionHandler.string(expressionStr, (currentExpression.staticText !== false));
expressionHandler.string(expressionStr, (currentExpression.isStringLiteral !== false));

@@ -1001,3 +1010,3 @@ _leaveExpressionState();

// We encountered nested placeholder...
currentExpression.staticText = false;
currentExpression.isStringLiteral = false;
} else {

@@ -1004,0 +1013,0 @@ expressionStr += ch;

var CODE_NEWLINE = 10;
var NUMBER_REGEX = /^[\-\+]?\d*(?:\.\d+)?(?:e[\-\+]?\d+)?$/;

@@ -7,2 +8,19 @@ function _removeDelimitersFromArgument(arg) {

function _updateAttributeLiteralValue(attr) {
var expression = attr.expression;
if (expression.length === 0) {
attr.literalValue = '';
} else if (expression === 'true') {
attr.literalValue = true;
} else if (expression === 'false') {
attr.literalValue = false;
} else if (expression === 'null') {
attr.literalValue = null;
} else if (expression === 'undefined') {
attr.literalValue = undefined;
} else if (NUMBER_REGEX.test(expression)) {
attr.literalValue = Number(expression);
}
}
exports.createNotifiers = function(parser, listeners) {

@@ -59,17 +77,22 @@ return {

// set the staticText property for attributes that are simple
// string values...
// set the literalValue property for attributes that are simple
// string simple values or simple literal values
var i = attributes.length;
while(--i >= 0) {
var attr = attributes[i];
if (attr.possibleStaticText) {
// if possib
if (attr.isStringLiteral) {
var expression = attr.expression;
attr.staticText = expression.substring(1, expression.length - 1);
attr.literalValue = expression.substring(1, expression.length - 1);
} else if (attr.isSimpleLiteral) {
_updateAttributeLiteralValue(attr);
}
if (attr.arguments) {
attr.arguments = _removeDelimitersFromArgument(attr.arguments);
if (attr.argument) {
attr.argument = _removeDelimitersFromArgument(attr.argument);
}
delete attr.possibleStaticText;
delete attr.isStringLiteral;
delete attr.isSimpleLiteral;
}

@@ -84,3 +107,3 @@

if (elementArguments) {
event.arguments = elementArguments;
event.argument = elementArguments;
}

@@ -87,0 +110,0 @@

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

},
"version": "1.0.2"
"version": "1.0.3"
}

@@ -189,3 +189,3 @@ htmljs-parser

**EXAMPLE: Tag with simple string attribute**
**EXAMPLE: Tag with literal attribute values**

@@ -195,3 +195,3 @@ INPUT:

```html
<div class="demo">
<div class="demo" disabled=false data-number=123>
```

@@ -209,3 +209,13 @@

expression: '"demo"',
staticText: 'demo'
literalValue: 'demo'
},
{
name: 'disabled',
expression: 'false',
literalValue: false
},
{
name: 'data-number',
expression: '123',
literalValue: 123
}

@@ -239,3 +249,3 @@ ]

**EXAMPLE: Tag with arguments**
**EXAMPLE: Tag with an argument**

@@ -254,3 +264,3 @@ INPUT:

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

@@ -260,3 +270,3 @@ }

**EXAMPLE: Attribute arguments**
**EXAMPLE: Attribute an argument**

@@ -278,3 +288,3 @@ INPUT:

name: 'if',
arguments: 'x > y'
argument: 'x > y'
}

@@ -281,0 +291,0 @@ ]

@@ -418,3 +418,4 @@ var chai = require('chai');

name: 'c',
expression: ''
expression: '',
literalValue: ''
},

@@ -497,3 +498,4 @@ {

name: 'a',
expression: '1'
expression: '1',
literalValue: 1
}

@@ -609,3 +611,4 @@ ]

name: 'data',
expression: '123'
expression: '123',
literalValue: 123
},

@@ -636,3 +639,3 @@ {

expression: '"\nabc\n124"',
staticText: '\nabc\n124'
literalValue: '\nabc\n124'
}

@@ -643,2 +646,149 @@ ]

});
describe('Attribute Literal Values', function() {
it('should recognize true literal', function() {
parse([
'<div data=true>'
], [
{
type: 'opentag',
name: 'div',
attributes: [
{
name: 'data',
expression: 'true',
literalValue: true
}
]
}
]);
});
it('should recognize false literal', function() {
parse([
'<div data=false>'
], [
{
type: 'opentag',
name: 'div',
attributes: [
{
name: 'data',
expression: 'false',
literalValue: false
}
]
}
]);
});
it('should recognize undefined literal', function() {
parse([
'<div data=undefined>'
], [
{
type: 'opentag',
name: 'div',
attributes: [
{
name: 'data',
expression: 'undefined',
literalValue: undefined
}
]
}
]);
});
it('should recognize null literal', function() {
parse([
'<div data=null>'
], [
{
type: 'opentag',
name: 'div',
attributes: [
{
name: 'data',
expression: 'null',
literalValue: null
}
]
}
]);
});
it('should recognize number literal', function() {
parse([
'<div data=1 data=.5 data=1.5 data=1.5e10 data=1.5e+10 data=1.5e-10 data=-1 data=-.5 data=-1.5 data=-1.5e10 data=-1.5e+10 data=-1.5e-10>'
], [
{
type: 'opentag',
name: 'div',
attributes: [
{
name: 'data',
expression: '1',
literalValue: 1
},
{
name: 'data',
expression: '.5',
literalValue: .5
},
{
name: 'data',
expression: '1.5',
literalValue: 1.5
},
{
name: 'data',
expression: '1.5e10',
literalValue: 1.5e10
},
{
name: 'data',
expression: '1.5e+10',
literalValue: 1.5e+10
},
{
name: 'data',
expression: '1.5e-10',
literalValue: 1.5e-10
},
{
name: 'data',
expression: '-1',
literalValue: -1
},
{
name: 'data',
expression: '-.5',
literalValue: -.5
},
{
name: 'data',
expression: '-1.5',
literalValue: -1.5
},
{
name: 'data',
expression: '-1.5e10',
literalValue: -1.5e10
},
{
name: 'data',
expression: '-1.5e+10',
literalValue: -1.5e+10
},
{
name: 'data',
expression: '-1.5e-10',
literalValue: -1.5e-10
}
]
}
]);
});
});
});

@@ -1140,3 +1290,3 @@

expression: '"simple"',
staticText: 'simple'
literalValue: 'simple'
}

@@ -1147,19 +1297,2 @@ ]

});
it('should not recognize static numeric attributes', function() {
parse([
'<div class=123>'
], [
{
type: 'opentag',
name: 'div',
attributes: [
{
name: 'class',
expression: '123'
}
]
}
]);
});
});

@@ -1175,3 +1308,3 @@

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

@@ -1189,3 +1322,3 @@ }

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

@@ -1203,3 +1336,3 @@ }

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

@@ -1220,3 +1353,3 @@ }

name: 'if',
arguments: 'x > y'
argument: 'x > y'
}

@@ -1238,3 +1371,3 @@ ]

name: 'if',
arguments: 'x > y'
argument: 'x > y'
}

@@ -1253,7 +1386,7 @@ ]

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

@@ -1280,3 +1413,3 @@ ]

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

@@ -1305,3 +1438,3 @@ }

name: 'for',
arguments: 'var i = 0; i < 10; i++'
argument: 'var i = 0; i < 10; i++'
}

@@ -1308,0 +1441,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