Skip to content
Open
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
5 changes: 5 additions & 0 deletions .changeset/fine-flies-drum.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@vivliostyle/cli': patch
---

Fix error when input file is on different drive on Windows
14 changes: 10 additions & 4 deletions src/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,12 +122,16 @@ export async function getSourceUrl({
'viewerInput' | 'base' | 'workspaceDir' | 'rootUrl'
>) {
let input: string;
let isUrlPath = false;
switch (viewerInput.type) {
case 'webpub':
input = viewerInput.manifestPath;
break;
case 'webbook':
input = viewerInput.webbookEntryUrl;
// webbookEntryUrl is already a URL path (e.g., "/vivliostyle/test.html")
// or a full URL (e.g., "https://example.com/test.html")
isUrlPath = !isValidUri(input);
break;
case 'epub-opf':
input = viewerInput.epubOpfPath;
Expand All @@ -145,10 +149,12 @@ export async function getSourceUrl({
return (
isValidUri(input)
? new URL(input)
: new URL(
upath.posix.join(base, upath.relative(workspaceDir, input)),
rootUrl,
)
: isUrlPath
? new URL(input, rootUrl)
: new URL(
upath.posix.join(base, upath.relative(workspaceDir, input)),
rootUrl,
)
).href;
}

Expand Down
3 changes: 2 additions & 1 deletion src/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,8 @@ export function pathEquals(path1: string, path2: string): boolean {

export function pathContains(parentPath: string, childPath: string): boolean {
const rel = upath.relative(parentPath, childPath);
return rel !== '' && !rel.startsWith('..');
// If relative path is absolute (different drives on Windows), they are not related
return rel !== '' && !rel.startsWith('..') && !upath.isAbsolute(rel);
}

export function isValidUri(str: string): boolean {
Expand Down