Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 30 additions & 16 deletions js/jsonld.js
Original file line number Diff line number Diff line change
Expand Up @@ -8131,35 +8131,49 @@ jsonld.url.parse = function(str, parser) {
* @param hasAuthority true if the URL has an authority, false if not.
*/
function _removeDotSegments(path, hasAuthority) {
var rval = '';
// RFC 3986 5.2.4 (reworked)

if(path.indexOf('/') === 0) {
rval = '/';
// empty path shortcut
if(path.length === 0) {
return '';
}

// RFC 3986 5.2.4 (reworked)
var input = path.split('/');
var output = [];

while(input.length > 0) {
if(input[0] === '.' || (input[0] === '' && input.length > 1)) {
input.shift();
var next = input.shift();
var done = input.length === 0;

if(next === '.') {
if(done) {
// ensure output has trailing /
output.push('');
}
continue;
}
if(input[0] === '..') {
input.shift();
if(hasAuthority ||
(output.length > 0 && output[output.length - 1] !== '..')) {
output.pop();
} else {
// leading relative URL '..'
output.push('..');

if(next === '..') {
output.pop();
if(done) {
// ensure output has trailing /
output.push('');
}
continue;
}
output.push(input.shift());

output.push(next);
}

// ensure output has leading /
if(output.length > 0 && output[0] !== '') {
output.unshift('');
}
if(output.length === 1 && output[0] === '') {
return '/';
}

return rval + output.join('/');
return output.join('/');
}

if(_nodejs) {
Expand Down
4 changes: 1 addition & 3 deletions tests/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -159,9 +159,7 @@ var TEST_TYPES = {
compare: compareExpectedNQuads
},
'jld:ToRDFTest': {
skip: {
regex: [/RFC3986/]
},
skip: {},
fn: 'toRDF',
params: [
readTestUrl('input'),
Expand Down