@@ -20,8 +20,8 @@ import { JSONPath } from 'jsonpath-plus';
20
20
21
21
import * as API from '../api.js' ;
22
22
import * as Environments from '../environments/environments.js' ;
23
-
24
23
import * as Utils from '../utils.js' ;
24
+ import { sanitizeHTML } from '../utils.js' ;
25
25
import * as Fields from './fields.js' ;
26
26
import * as Things from './things.js' ;
27
27
import * as ThingsSSE from './thingsSSE.js' ;
@@ -75,12 +75,14 @@ function onThingsTableClicked(event) {
75
75
/**
76
76
* Tests if the search filter is an RQL. If yes, things search is called otherwise just things get
77
77
* @param {String } filter search filter string containing an RQL or a thingId
78
+ * @param rqlFilterCallback a callback to invoke when the passed `filter` was a valid RQL statement
78
79
*/
79
- export function searchTriggered ( filter ) {
80
+ export function searchTriggered ( filter : string , rqlFilterCallback : ( ) => void ) {
80
81
lastSearch = filter ;
81
82
const regex = / ^ ( e q \( | n e \( | g t \( | g e \( | l t \( | l e \( | i n \( | l i k e \( | i l i k e \( | e x i s t s \( | a n d \( | o r \( | n o t \( ) .* / ;
82
83
if ( filter === '' || regex . test ( filter ) ) {
83
84
searchThings ( filter ) ;
85
+ rqlFilterCallback ( ) ;
84
86
} else {
85
87
getThings ( [ filter ] ) ;
86
88
}
@@ -104,7 +106,7 @@ export function performLastSearch() {
104
106
if ( lastSearch === 'pinned' ) {
105
107
pinnedTriggered ( ) ;
106
108
} else {
107
- searchTriggered ( lastSearch ) ;
109
+ searchTriggered ( lastSearch , ( ) => null ) ;
108
110
}
109
111
}
110
112
@@ -113,7 +115,7 @@ export function performLastSearch() {
113
115
* @param {Array } thingIds Array of thingIds
114
116
*/
115
117
export function getThings ( thingIds ) {
116
- dom . thingsTableBody . innerHTML = '' ;
118
+ dom . thingsTableBody . textContent = '' ;
117
119
const fieldsQueryParameter = Fields . getQueryParameter ( ) ;
118
120
if ( thingIds . length > 0 ) {
119
121
API . callDittoREST ( 'GET' ,
@@ -134,8 +136,8 @@ export function getThings(thingIds) {
134
136
135
137
function resetAndClearViews ( retainThing = false ) {
136
138
theSearchCursor = null ;
137
- dom . thingsTableHead . innerHTML = '' ;
138
- dom . thingsTableBody . innerHTML = '' ;
139
+ dom . thingsTableHead . textContent = '' ;
140
+ dom . thingsTableBody . textContent = '' ;
139
141
if ( ! retainThing ) {
140
142
Things . setTheThing ( null ) ;
141
143
}
@@ -187,7 +189,7 @@ function searchThings(filter, isMore = false) {
187
189
188
190
function addMoreToThingList ( ) {
189
191
const moreCell = dom . thingsTableBody . insertRow ( ) . insertCell ( - 1 ) ;
190
- moreCell . innerHTML = 'load more...' ;
192
+ moreCell . textContent = 'load more...' ;
191
193
moreCell . colSpan = dom . thingsTableBody . rows [ 0 ] . childElementCount ;
192
194
moreCell . style . textAlign = 'center' ;
193
195
moreCell . style . cursor = 'pointer' ;
@@ -225,7 +227,7 @@ function fillThingsTable(thingsList) {
225
227
}
226
228
227
229
function fillHeaderRow ( ) {
228
- dom . thingsTableHead . innerHTML = '' ;
230
+ dom . thingsTableHead . textContent = '' ;
229
231
// Utils.addCheckboxToRow(dom.thingsTableHead, 'checkboxHead', false, null);
230
232
Utils . insertHeaderCell ( dom . thingsTableHead , '' ) ;
231
233
Utils . insertHeaderCell ( dom . thingsTableHead , 'Thing ID' ) ;
@@ -302,7 +304,7 @@ export function updateTableRow(thingUpdateJson) {
302
304
path : path ,
303
305
} ) ;
304
306
if ( elem . length !== 0 ) {
305
- cell . innerHTML = elem [ 0 ] ;
307
+ cell . innerHTML = sanitizeHTML ( elem [ 0 ] ) ;
306
308
}
307
309
}
308
310
} ) ;
0 commit comments