Repository navigation
Expand file tree
/
Copy pathupstream.patch
More file actions
108 lines (102 loc) · 4.06 KB
/
Copy pathupstream.patch
File metadata and controls
108 lines (102 loc) · 4.06 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
diff --git a/src/Sidepanel/Sidepanel.tsx b/src/Sidepanel/Sidepanel.tsx
index 4e5da21a..c62126ab 100644
--- a/src/Sidepanel/Sidepanel.tsx
+++ b/src/Sidepanel/Sidepanel.tsx
@@ -164,6 +164,7 @@ function SidepanelInner(
}: Props,
ref: React.ForwardedRef<SidepanelRef>
): JSX.Element {
+ const titleId = React.useId();
const [isExpanded, setIsExpanded] = React.useState(false);
const [sidepanelState, setSidepanelState] =
React.useState<SidepanelState>('new-conversation');
@@ -408,6 +409,7 @@ function SidepanelInner(
} as React.CSSProperties
}
role="dialog"
+ aria-labelledby={titleId}
tabIndex={-1}
ref={setSidepanelContainer}
>
@@ -416,6 +418,8 @@ function SidepanelInner(
className={`DocSearch-Sidepanel ${sidepanelState}`}
>
<SidepanelHeader
+ titleId={titleId}
+ translations={translations.header}
sidepanelState={sidepanelState}
exchanges={exchanges}
setSidepanelState={setSidepanelState}
diff --git a/src/Sidepanel/SidepanelHeader.tsx b/src/Sidepanel/SidepanelHeader.tsx
index a398d866..6c845c46 100644
--- a/src/Sidepanel/SidepanelHeader.tsx
+++ b/src/Sidepanel/SidepanelHeader.tsx
@@ -54,6 +54,7 @@ export type HeaderTranslations = Partial<{
}>;
type SidepanelHeaderProps = {
+ titleId: string;
sidepanelState: SidepanelState;
exchanges: Exchange[];
setSidepanelState: (state: SidepanelState) => void;
@@ -67,6 +68,7 @@ type SidepanelHeaderProps = {
export const SidepanelHeader = React.memo(
({
+ titleId,
sidepanelState,
exchanges,
setSidepanelState,
@@ -143,7 +145,7 @@ export const SidepanelHeader = React.memo(
<div className="DocSearch-Sidepanel-Header--center">
<BackButton disabled={isStreaming} onBack={onBack} />
<SparklesIcon className="DocSearch-Sidepanel-Header-TitleIcon" />
- <h2 className="DocSearch-Sidepanel-Title">{header}</h2>
+ <h2 id={titleId} className="DocSearch-Sidepanel-Title">{header}</h2>
</div>
<div className="DocSearch-Sidepanel-Header--right">
{sidepanelState !== 'conversation-history' &&
diff --git a/src/utils/markdown.ts b/src/utils/markdown.ts
index 5bc25966..15052f03 100644
--- a/src/utils/markdown.ts
+++ b/src/utils/markdown.ts
@@ -22,16 +22,18 @@ renderer.code = ({ text, lang = '', escaped }: Tokens.Code): string => {
`;
};
-renderer.link = ({ href, title, text }: Tokens.Link): string => {
+renderer.link = function ({ href, title, tokens }: Tokens.Link): string {
const safeHref = escapeHtml(sanitizeUrl(href));
- const textEscaped = escapeHtml(text);
+ // Render nested Markdown through the same safe renderers. Escaping the raw
+ // label turns linked screenshots and formatted labels into literal Markdown.
+ const content = this.parser.parseInline(tokens);
if (!safeHref) {
- return textEscaped;
+ return content;
}
const titleAttr = title ? ` title="${escapeHtml(title)}"` : '';
- return `<a href="${safeHref}"${titleAttr} target="_blank" rel="noopener noreferrer">${textEscaped}</a>`;
+ return `<a href="${safeHref}"${titleAttr} target="_blank" rel="noopener noreferrer">${content}</a>`;
};
renderer.image = ({ href, title, text }: Tokens.Image): string => {
diff --git a/src/utils/sanitize.ts b/src/utils/sanitize.ts
index 7213793e..445d2a2b 100644
--- a/src/utils/sanitize.ts
+++ b/src/utils/sanitize.ts
@@ -77,7 +77,10 @@ export function sanitizeUrl(url: string | null | undefined): string {
parsed.protocol === 'https:' ||
parsed.protocol === 'mailto:'
) {
- return normalized;
+ // Normalization is only for detecting unsafe schemes. Returning it would
+ // change valid encoded paths, query values, and fragments (for example,
+ // `Pro%20Features` becomes `ProFeatures`). Preserve the caller's URL.
+ return trimmed;
}
} catch {
return '';
diff --git a/src/version.ts b/src/version.ts
index 6f577f97..e92e8d8f 100644
--- a/src/version.ts
+++ b/src/version.ts
@@ -1 +1 @@
-export const version = '5.2.0';
+export const version = '5.2.0-phcode.2';