File tree Expand file tree Collapse file tree 1 file changed +12
-1
lines changed Expand file tree Collapse file tree 1 file changed +12
-1
lines changed Original file line number Diff line number Diff line change @@ -9,6 +9,15 @@ function capitalizeFirstLetter(string) {
9
9
return string . charAt ( 0 ) . toUpperCase ( ) + string . slice ( 1 ) ;
10
10
}
11
11
12
+ function htmlEscape ( str ) {
13
+ return String ( str )
14
+ . replace ( / & / g, "&" )
15
+ . replace ( / " / g, """ )
16
+ . replace ( / ' / g, "'" )
17
+ . replace ( / < / g, "<" )
18
+ . replace ( / > / g, ">" ) ;
19
+ }
20
+
12
21
/*
13
22
Our `Result` component expects result fields to be formatted in an object
14
23
like:
@@ -19,7 +28,9 @@ function capitalizeFirstLetter(string) {
19
28
*/
20
29
function formatResultFields ( result ) {
21
30
return Object . keys ( result . data ) . reduce ( ( acc , n ) => {
22
- let value = result . getSnippet ( n ) ;
31
+ // Fallback to raw values here, because non-string fields
32
+ // will not have a snippet fallback. Raw values MUST be html escaped.
33
+ let value = result . getSnippet ( n ) || htmlEscape ( result . getRaw ( n ) ) ;
23
34
value = Array . isArray ( value ) ? value . join ( ", " ) : value ;
24
35
acc [ `${ capitalizeFirstLetter ( n ) } ` ] = value ;
25
36
return acc ;
You can’t perform that action at this time.
0 commit comments