Skip to content

Commit

Permalink
utils: perform portable path sanitisation of URLs
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
compnerd committed Aug 10, 2023
1 parent a3c3a48 commit 7e57034
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions src/utils/data.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import { normalizePath } from 'docc-render/utils/assets';
import {
queryStringForParams, areEquivalentLocations, getAbsoluteUrl,
} from 'docc-render/utils/url-helper';
import { getSetting } from 'docc-render/utils/theme-settings';
import emitWarningForSchemaVersionMismatch from 'docc-render/utils/schema-version-check';
import RedirectError from 'docc-render/errors/RedirectError';
import FetchError from 'docc-render/errors/FetchError';
Expand Down Expand Up @@ -56,8 +57,15 @@ export async function fetchData(path, params = {}, options = {}) {
}

function createDataPath(path) {
const dataPath = path.replace(/\/$/, '');
return `${normalizePath(['/data', dataPath])}.json`;
function filePathFor(path) {
if (process.env.VUE_APP_TARGET !== 'ide' &&
getSetting(['features', 'docs', 'portablePaths', 'enable'], false)) {
return path.replace(/\/$/, "").replace(/[<>:"\/\\|*]/, "_");
} else {
return path.replace(/\/$/, "")
}
}
return `${normalizePath(['/data', filePathFor(path)])}.json`;
}

/**
Expand Down

0 comments on commit 7e57034

Please sign in to comment.