Skip to content
Merged
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: 3 additions & 17 deletions packages/docusaurus/src/server/routes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -123,23 +123,9 @@ ${indent(subroutesCodeStrings.join(',\n'))}
}

Object.entries(props).forEach(([propName, propValue]) => {
// Inspired by https://github.com/armanozak/should-quote/blob/main/packages/should-quote/src/lib/should-quote.ts
const shouldQuote = ((key: string) => {
// Pre-sanitation to prevent injection
if (/[.,;:}/\s]/.test(key)) {
return true;
}
try {
// If this key can be used in an expression like ({a:0}).a
// eslint-disable-next-line no-eval
eval(`({${key}:0}).${key}`);
return false;
} catch {
return true;
}
})(propName);
// Escape quotes as well
const key = shouldQuote ? JSON.stringify(propName) : propName;
const isIdentifier =

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what about the test 😅 not really confident it works here, but it looks like it does

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We already have decent tests for this, plus this is a direct translation of the spec, so I won't worry about it too much.

/^[$_\p{ID_Start}][$\u200c\u200d\p{ID_Continue}]*$/u.test(propName);
const key = isIdentifier ? propName : JSON.stringify(propName);
parts.push(`${key}: ${JSON.stringify(propValue)}`);
});

Expand Down