Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
node_modules
package-lock.json
.idea
lerna-debug.log
yarn-error.log
Expand Down
9 changes: 7 additions & 2 deletions lib/Resolve.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,15 @@ export function resolve(relativeIRI: string, baseIRI?: string): string {
return removeDotSegmentsOfPath(relativeIRI, relativeColonPos);
}

// Ignore baseIRI if the value is absolute
// Ignore baseIRI if the value is absolute.
// Per RFC 3986, a URI scheme cannot contain a '/', so if a '/' appears before the first ':',
// the IRI is a relative path (not an absolute IRI).
const valueColonPos: number = relativeIRI.indexOf(':');
if (valueColonPos >= 0) {
return removeDotSegmentsOfPath(relativeIRI, valueColonPos);
const valueSlashPos: number = relativeIRI.indexOf('/');
if (valueSlashPos < 0 || valueColonPos < valueSlashPos) {
return removeDotSegmentsOfPath(relativeIRI, valueColonPos);
}
}

// At this point, the baseIRI MUST be absolute, otherwise we error
Expand Down
15 changes: 15 additions & 0 deletions test/Resolve-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -441,6 +441,21 @@ describe('#resolve', () => {
expect(resolve('../.../../../', 'http://example.org/a/b/c/'))
.toEqual('http://example.org/a/');
});

it('create an IRI from a relative IRI with a slash before a colon and a baseIRI with trailing slash', () => {
expect(resolve('x/y:z', 'http://base.org/path/'))
.toEqual('http://base.org/path/x/y:z');
});

it('create an IRI from a relative IRI with a slash before a colon and a baseIRI without trailing slash', () => {
expect(resolve('x/y:z', 'http://base.org/path'))
.toEqual('http://base.org/x/y:z');
});

it('create an IRI from a relative IRI with multiple colons after a slash', () => {
expect(resolve('x/y:z:w', 'http://base.org/path/'))
.toEqual('http://base.org/path/x/y:z:w');
});
});

describe('#removeDotSegments', () => {
Expand Down