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) {
99 return string . charAt ( 0 ) . toUpperCase ( ) + string . slice ( 1 ) ;
1010}
1111
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+
1221/*
1322 Our `Result` component expects result fields to be formatted in an object
1423 like:
@@ -19,7 +28,9 @@ function capitalizeFirstLetter(string) {
1928*/
2029function formatResultFields ( result ) {
2130 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 ) ) ;
2334 value = Array . isArray ( value ) ? value . join ( ", " ) : value ;
2435 acc [ `${ capitalizeFirstLetter ( n ) } ` ] = value ;
2536 return acc ;
You can’t perform that action at this time.
0 commit comments