Skip to content

Commit 7e57034

Browse files
committed
utils: perform portable path sanitisation of URLs
Some file systems have restrictions on character sets which are valid file name characters. Add a filter for the Windows file system character set restrictions. We replace them with `_` to match the behaviour in the DocC bundle generation after swiftlang/swift-docc#668. Conditionally enable the new portable paths based upon a setting in `theme-settings.json` to provide a means for compatibility.
1 parent a3c3a48 commit 7e57034

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

src/utils/data.js

+10-2
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import { normalizePath } from 'docc-render/utils/assets';
1212
import {
1313
queryStringForParams, areEquivalentLocations, getAbsoluteUrl,
1414
} from 'docc-render/utils/url-helper';
15+
import { getSetting } from 'docc-render/utils/theme-settings';
1516
import emitWarningForSchemaVersionMismatch from 'docc-render/utils/schema-version-check';
1617
import RedirectError from 'docc-render/errors/RedirectError';
1718
import FetchError from 'docc-render/errors/FetchError';
@@ -56,8 +57,15 @@ export async function fetchData(path, params = {}, options = {}) {
5657
}
5758

5859
function createDataPath(path) {
59-
const dataPath = path.replace(/\/$/, '');
60-
return `${normalizePath(['/data', dataPath])}.json`;
60+
function filePathFor(path) {
61+
if (process.env.VUE_APP_TARGET !== 'ide' &&
62+
getSetting(['features', 'docs', 'portablePaths', 'enable'], false)) {
63+
return path.replace(/\/$/, "").replace(/[<>:"\/\\|*]/, "_");
64+
} else {
65+
return path.replace(/\/$/, "")
66+
}
67+
}
68+
return `${normalizePath(['/data', filePathFor(path)])}.json`;
6169
}
6270

6371
/**

0 commit comments

Comments
 (0)