Skip to content

Commit a525dd2

Browse files
tplookerdavidlehn
authored andcommitted
feat: add support for @base being './'
1 parent ba0aca9 commit a525dd2

File tree

3 files changed

+21
-2
lines changed

3 files changed

+21
-2
lines changed

lib/context.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1050,7 +1050,7 @@ function _expandIri(activeCtx, value, relativeTo, localCtx, defined, options) {
10501050
if(relativeTo.base && '@base' in activeCtx) {
10511051
if(activeCtx['@base']) {
10521052
// The null case preserves value as potentially relative
1053-
return prependBase(prependBase(options.base, activeCtx['@base']), value);
1053+
value = prependBase(prependBase(options.base, activeCtx['@base']), value);
10541054
}
10551055
} else if(relativeTo.base) {
10561056
value = prependBase(options.base, value);

lib/expand.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -528,7 +528,6 @@ async function _expandObject({
528528
]));
529529
}
530530
_validateTypeValue(value, options.isFrame);
531-
532531
_addValue(
533532
expandedParent, '@type',
534533
_asArray(value).map(v =>

tests/misc.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -680,4 +680,24 @@ describe('expansionMap', () => {
680680

681681
assert.equal(expansionMapCalled, true);
682682
});
683+
684+
it("should be called on relative iri when @base value is './'", async () => {
685+
const docWithRelativeIriId = {
686+
'@context': {
687+
"@base": "./",
688+
},
689+
'@id': "absoluteiri",
690+
};
691+
692+
let expansionMapCalled = false;
693+
const expansionMap = info => {
694+
if(info.relativeIri === '/absoluteiri') {
695+
expansionMapCalled = true;
696+
}
697+
};
698+
699+
await jsonld.expand(docWithRelativeIriId, {expansionMap});
700+
701+
assert.equal(expansionMapCalled, true);
702+
});
683703
});

0 commit comments

Comments
 (0)