Skip to content
This repository was archived by the owner on Dec 30, 2022. It is now read-only.

Commit 61341a9

Browse files
committed
feat(store): escape results when fetched
1 parent e78cacd commit 61341a9

File tree

2 files changed

+42
-1
lines changed

2 files changed

+42
-1
lines changed

src/__tests__/store.js

+34
Original file line numberDiff line numberDiff line change
@@ -333,4 +333,38 @@ describe('Store', () => {
333333

334334
expect(store._helper.getPage()).toEqual(4);
335335
});
336+
337+
test('should allow to fetch sanitized results', () => {
338+
const store = createStore();
339+
store._helper.lastResults = {
340+
hits: [
341+
{
342+
objectID: '1',
343+
name: 'test',
344+
_highlightResult: {
345+
name: {
346+
value:
347+
"__ais-highlight__te__/ais-highlight__st<script>alert('test')</script>",
348+
matchLevel: 'full',
349+
},
350+
},
351+
},
352+
],
353+
};
354+
355+
const results = store.results;
356+
expect(results).toEqual([
357+
{
358+
objectID: '1',
359+
name: 'test',
360+
_highlightResult: {
361+
name: {
362+
value:
363+
'<em>te</em>st&lt;script&gt;alert(&#39;test&#39;)&lt;/script&gt;',
364+
matchLevel: 'full',
365+
},
366+
},
367+
},
368+
]);
369+
});
336370
});

src/store.js

+8-1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ import {
66
unserialize as unserializeHelper,
77
} from './helper-serializer';
88

9+
import sanitizeResults from './sanitize-results';
10+
911
export const FACET_AND = 'and';
1012
export const FACET_OR = 'or';
1113
export const FACET_TREE = 'tree';
@@ -137,7 +139,12 @@ export class Store {
137139
return [];
138140
}
139141

140-
return this._helper.lastResults.hits;
142+
return sanitizeResults(
143+
this._helper.lastResults.hits,
144+
HIGHLIGHT_PRE_TAG,
145+
HIGHLIGHT_POST_TAG,
146+
'em'
147+
);
141148
}
142149

143150
get page() {

0 commit comments

Comments
 (0)