Skip to content

Commit

Permalink
fix(specmap): add backward compatible relative URI Reference resoluti…
Browse files Browse the repository at this point in the history
…on (#3148)

Refs #3147
  • Loading branch information
char0n authored Sep 18, 2023
1 parent 526f5c6 commit 1b17ba1
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion src/specmap/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,18 @@ export function generateAbsoluteRefPatches(

export function absolutifyPointer(pointer, baseUrl) {
const [urlPart, fragmentPart] = pointer.split('#');
const newRefUrlPart = url.resolve(baseUrl || '', urlPart || '');
const safeBaseUrl = baseUrl ?? '';
const safeUrlPart = urlPart ?? '';
let newRefUrlPart;

if (!url.isHttpUrl(safeBaseUrl)) {
const cwd = url.cwd();
const absoluteBaseUrl = url.resolve(cwd, safeBaseUrl);
const absoluteRefUrlPart = url.resolve(absoluteBaseUrl, safeUrlPart);
newRefUrlPart = absoluteRefUrlPart.replace(cwd, '');
} else {
newRefUrlPart = url.resolve(safeBaseUrl, safeUrlPart);
}

return fragmentPart ? `${newRefUrlPart}#${fragmentPart}` : newRefUrlPart;
}

0 comments on commit 1b17ba1

Please sign in to comment.