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

htmljs-parser

Package Overview
Dependencies
Maintainers
2
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.8 to 1.1.0

6

html-tags.js

@@ -1,2 +0,2 @@

var startTagOnly = {};
var openTagOnly = {};
var requireClosingTag = {};

@@ -20,3 +20,3 @@

].forEach(function(tagName) {
startTagOnly[tagName] = true;
openTagOnly[tagName] = true;
});

@@ -124,3 +124,3 @@

exports.startTagOnly = startTagOnly;
exports.openTagOnly = openTagOnly;
exports.requireClosingTag = requireClosingTag;

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

},
"version": "1.0.8"
"version": "1.1.0"
}
[
{
"type": "opentag",
"tagName": "div",
"tagName": "assign",
"attributes": [
{
"name": "foo",
"expression": "'\\\"hello\\\"'",
"literalValue": "\"hello\""
"name": "data.someArray[0].doSomething",
"argument": "'test'"
},
{
"name": ".hello",
"expression": "1+1"
}
],
"pos": 0
"pos": 0,
"selfClosed": true
},
{
"type": "text",
"text": "\n Hello World!\n"
},
{
"type": "closetag",
"tagName": "div"
"tagName": "assign",
"selfClosed": true
}
]

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

var attributes = event.attributes;
return '<' + tagName + attributesToString(attributes) + '>';
var openTagOnly = event.openTagOnly === true;
var selfClosed = event.selfClosed === true;
return '<' + tagName + attributesToString(attributes) + (openTagOnly ? ' OPEN_ONLY' : '') + (selfClosed ? ' SELF_CLOSED' : '') + '>';
}

@@ -84,9 +86,9 @@

'text:A',
'<img src="image1.png">',
'<img src="image1.png" OPEN_ONLY>',
'</img>',
'text:B',
'<img src="image2.png">',
'<img src="image2.png" OPEN_ONLY>',
'</img>',
'text:C',
'<img src="image3.png">',
'<img src="image3.png" OPEN_ONLY>',
'</img>',

@@ -98,3 +100,3 @@ 'text:D',

it('should allow unrecognized tags to be self-closing', function() {
it('should allow unrecognized tags to be open tag only', function() {
testParser(

@@ -105,9 +107,9 @@ '<div> A <foo-img src="image1.png"> B <foo-img src="image2.png"> C <foo-img src="image3.png"> D </div>',

'text:A',
'<foo-img src="image1.png">',
'<foo-img src="image1.png" OPEN_ONLY>',
'</foo-img>',
'text:B',
'<foo-img src="image2.png">',
'<foo-img src="image2.png" OPEN_ONLY>',
'</foo-img>',
'text:C',
'<foo-img src="image3.png">',
'<foo-img src="image3.png" OPEN_ONLY>',
'</foo-img>',

@@ -126,3 +128,3 @@ 'text:D',

'</div>',
'<img src="image1.png">',
'<img src="image1.png" OPEN_ONLY>',
'</img>'

@@ -156,3 +158,3 @@ ]);

'<div>',
'<img src="image1.png">',
'<img src="image1.png" OPEN_ONLY>',
'</img>',

@@ -201,2 +203,11 @@ '</div>'

it('should correct a tag that is not allowed to be self-closing', function() {
testParser(
'<div class="foo"/>',
[
'<div class="foo">',
'</div>'
]);
});
// it('should include line number in error', function() {

@@ -203,0 +214,0 @@ // testParser(

@@ -14,3 +14,3 @@ 'use strict';

var startTagOnly = htmlTags.startTagOnly;
var openTagOnly = htmlTags.openTagOnly;
var requireClosingTag = htmlTags.requireClosingTag;

@@ -110,3 +110,4 @@

type: 'closetag',
tagName: this.tagName
tagName: this.tagName,
selfClosing: true
};

@@ -200,2 +201,10 @@ }

onopentag(event) {
var tagName = event.tagName;
var isOpenTagOnly = openTagOnly[tagName.toLowerCase()];
if (isOpenTagOnly) {
delete event.selfClosed;
event.openTagOnly = true;
}
var newNode = new ElementNode(event);

@@ -206,6 +215,9 @@ var parent = stack[stack.length - 1];

var tagName = event.tagName;
if (event.selfClosed || startTagOnly[tagName.toLowerCase()]) {
if (event.selfClosed || isOpenTagOnly) {
stack.length--;
}
if (event.selfClosed && requireClosingTag[tagName.toLowerCase()]) {
delete event.selfClosed;
}
},

@@ -222,3 +234,3 @@

if (startTagOnly[tagName.toLowerCase()]) {
if (openTagOnly[tagName.toLowerCase()]) {
return notifyError(

@@ -242,2 +254,4 @@ new Error('Invalid closing tag: </' + tagName + '>'),

curNode.event.openTagOnly = true;
do {

@@ -269,2 +283,4 @@ if (curNode.tagName && requireClosingTag[curNode.getTagName().toLowerCase()]) {

return;
} else {
curNode.event.openTagOnly = true;
}

@@ -271,0 +287,0 @@ } while(true);

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