From 7e57034d751f6f6aec8f1e7591bf2e0888591e79 Mon Sep 17 00:00:00 2001 From: Saleem Abdulrasool Date: Sat, 22 Jul 2023 11:22:24 -0700 Subject: [PATCH] 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 apple/swift-docc#668. Conditionally enable the new portable paths based upon a setting in `theme-settings.json` to provide a means for compatibility. --- src/utils/data.js | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/utils/data.js b/src/utils/data.js index fc1440457..f0ffb2596 100644 --- a/src/utils/data.js +++ b/src/utils/data.js @@ -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'; @@ -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`; } /**