microdata-node
Advanced tools
Comparing version 0.0.13 to 0.0.14
@@ -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' ] | ||
}); | ||
}); | ||
}); |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
25329
637
2
+ Addedis-absolute-url@^1.0.0
+ Addedis-absolute-url@1.0.0(transitive)