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

microdata-node

Package Overview
Dependencies
Maintainers
1
Versions
29
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

microdata-node - npm Package Compare versions

Comparing version 0.0.13 to 0.0.14

19

lib/index.js

@@ -6,2 +6,3 @@ 'use strict';

var unique = require('array-unique');
var isAbsoluteUrl = require('is-absolute-url');

@@ -23,2 +24,8 @@ function splitUnique(string) {

function resolveBase($, docBase) {
docBase = docBase || '';
var baseTagHref = $('base').attr('href') || '';
return urlUtil.resolve(docBase, baseTagHref);
}
function parse($, $nodes, config) {

@@ -28,2 +35,3 @@

var items = [];
var base = resolveBase($, config.base);

@@ -89,8 +97,7 @@ function walkNodes($nodes, currentItem) {

function resolveUrlAttribute($node, attr) {
var relative = resolveAttribute($node, attr);
if (relative && config.base) {
return urlUtil.resolve(config.base, relative);
} else {
return relative;
}
var url = $node.attr(attr);
if (url === undefined) return '';
url = url.trim();
if (isAbsoluteUrl(url)) return url;
return urlUtil.resolve(base, url);
}

@@ -97,0 +104,0 @@

{
"name": "microdata-node",
"version": "0.0.13",
"version": "0.0.14",
"description": "Cheerio based microdata parser",

@@ -34,4 +34,5 @@ "main": "lib",

"dependencies": {
"array-unique": "^0.1.1"
"array-unique": "^0.1.1",
"is-absolute-url": "^1.0.0"
}
}

@@ -184,2 +184,28 @@ /* global describe, it */

it('handles absolute urls when no base is set', function () {
var $ = cheerio.load(
'<div itemscope>' +
' <a itemprop="property" href="http://www.example.com"></a>' +
'</div>'
);
var result = parser.parse($, null, { base: undefined });
assert.deepEqual(result.items[0].properties, {
property: [ 'http://www.example.com' ]
});
});
it('handles base tag for url properties', function () {
var $ = cheerio.load(
'<!doctype html>' +
'<head><base href="./base/"/></head>' +
'<body itemscope>' +
' <a itemprop="property" href="./relative"></a>' +
'</body>'
);
var result = parser.parse($, null, { base: 'http://www.example.com/' });
assert.deepEqual(result.items[0].properties, {
property: [ 'http://www.example.com/base/relative' ]
});
});
});
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