Skip to content

Commit

Permalink
Fix prismjs string template literal regex (#2719)
Browse files Browse the repository at this point in the history
Those regex were reporting to have some vulnerability for performance,
not sure if this fixes it but I think those were errors to start with
and this is the way the swift prism definition does with with `\(`
instead of `${`

---------

Co-authored-by: Mark Cowlishaw <[email protected]>
  • Loading branch information
timotheeguerin and markcowl authored Dec 5, 2023
1 parent 0b01d95 commit 211ca4f
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 5 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"changes": [
{
"packageName": "@typespec/playground",
"comment": "Add `noopener noreferrer` to footer external links",
"type": "none"
}
],
"packageName": "@typespec/playground"
}
2 changes: 2 additions & 0 deletions cspell.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ words:
- multis
- munge
- mylib
- noopener
- noreferrer
- nostdlib
- oapi
- oneof
Expand Down
2 changes: 1 addition & 1 deletion packages/playground/src/react/footer/footer-item.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export interface FooterItemProps {
export const FooterItem: FunctionComponent<FooterItemProps> = ({ children, link, className }) => {
const resolvedClassName = mergeClasses(style["footer-item"], className);
return link ? (
<a className={resolvedClassName} href={link} target="_blank">
<a className={resolvedClassName} href={link} target="_blank" rel="noopener noreferrer">
{children}
</a>
) : (
Expand Down
7 changes: 3 additions & 4 deletions packages/website/src/theme/typespec-lang-prism.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,23 +34,22 @@ const lang = {
},

string: [
// https://docs.swift.org/swift-book/LanguageGuide/StringsAndCharacters.html
{
pattern: new RegExp(
/(^|[^"#])/.source +
"(?:" +
// multi-line string
/"""(?:\\(?:\$\{(?:[^{}]|\$\{[^{}]*\})*\}|[^(])|[^\\"]|"(?!""))*"""/.source +
/"""(?:\$(?:\{(?:[^{}]|\{[^{}]*\})*\}|[^{])|[^$"]|"(?!""))*"""/.source +
"|" +
// single-line string
/"(?:\\(?:\$\{(?:[^{}]|\$\{[^{}]*\})*\}|\r\n|[^(])|[^\\\r\n"])*"/.source +
/"(?:\$(?:\{(?:[^{}]|\{[^{}]*\})*\}|\r\n|[^{])|[^$\r\n"])*"/.source +
")"
),
lookbehind: true,
greedy: true,
inside: {
interpolation: {
pattern: /(\$\{)(?:[^{}]|\$\{[^{}]*\})*(?=\})/,
pattern: /(\$\{)(?:[^{}]|\{[^{}]*\})*(?=\})/,
lookbehind: true,
inside: null, // see below
},
Expand Down

0 comments on commit 211ca4f

Please sign in to comment.