Skip to content
Open
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
20 changes: 17 additions & 3 deletions packages/docusaurus-plugin-stored-data/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,14 @@ const httpsPromise = (
const getData = async (location: string): Promise<string> => {
try {
new URL(location); // will throw if invalid URL

const response = await httpsPromise(location);
return response.body;
if (validateUrl(location)){
const response = await httpsPromise(location);
return response.body;
}
else{
throw "Location URI is not in the proper format";
}

} catch (error) {
// If it's just an invalid URL, let it fall through to check if it's a file
if (
Expand Down Expand Up @@ -78,6 +83,15 @@ const getData = async (location: string): Promise<string> => {
throw new Error(`Could not determine if ${location} is a URL or file`);
};


const validateUrl = (locationString : string): Boolean => {
try {
const url = new URL(locationString);
return url.protocol === "http:" || url.protocol === "https:";
} catch {
return false;
}
}
const pluginStoredData = (
_: LoadContext,
{ data = {} }: Options,
Expand Down