@@ -56,8 +56,7 @@ func NewLibrary() cel.Library {
5656// should avoid exposing additional functions as they will not be portable.
5757type library struct {}
5858
59- //nolint:funlen
60- func (l library ) CompileOptions () []cel.EnvOption {
59+ func (l library ) CompileOptions () []cel.EnvOption { //nolint:funlen,gocyclo
6160 return []cel.EnvOption {
6261 cel .TypeDescs (protoregistry .GlobalFiles ),
6362 cel .DefaultUTCTimeZone (true ),
@@ -258,7 +257,11 @@ func (l library) CompileOptions() []cel.EnvOption {
258257 if ! ok {
259258 return types .UnsupportedRefValConversionErr (rhs )
260259 }
261- return types .Bool (strings .Contains (lhs .Value ().(string ), substr ))
260+ value , ok := lhs .Value ().(string )
261+ if ! ok {
262+ return types .UnsupportedRefValConversionErr (lhs )
263+ }
264+ return types .Bool (strings .Contains (value , substr ))
262265 }),
263266 ),
264267 cel .MemberOverload ("contains_bytes" , []* cel.Type {cel .BytesType , cel .BytesType }, cel .BoolType ,
@@ -267,7 +270,11 @@ func (l library) CompileOptions() []cel.EnvOption {
267270 if ! ok {
268271 return types .UnsupportedRefValConversionErr (rhs )
269272 }
270- return types .Bool (bytes .Contains (lhs .Value ().([]byte ), substr ))
273+ value , ok := lhs .Value ().([]byte )
274+ if ! ok {
275+ return types .UnsupportedRefValConversionErr (lhs )
276+ }
277+ return types .Bool (bytes .Contains (value , substr ))
271278 }),
272279 ),
273280 ),
@@ -279,7 +286,11 @@ func (l library) CompileOptions() []cel.EnvOption {
279286 if ! ok {
280287 return types .UnsupportedRefValConversionErr (rhs )
281288 }
282- return types .Bool (strings .HasSuffix (lhs .Value ().(string ), suffix ))
289+ value , ok := lhs .Value ().(string )
290+ if ! ok {
291+ return types .UnsupportedRefValConversionErr (lhs )
292+ }
293+ return types .Bool (strings .HasSuffix (value , suffix ))
283294 }),
284295 ),
285296 cel .MemberOverload ("ends_with_bytes" , []* cel.Type {cel .BytesType , cel .BytesType }, cel .BoolType ,
@@ -288,7 +299,11 @@ func (l library) CompileOptions() []cel.EnvOption {
288299 if ! ok {
289300 return types .UnsupportedRefValConversionErr (rhs )
290301 }
291- return types .Bool (bytes .HasSuffix (lhs .Value ().([]byte ), suffix ))
302+ value , ok := lhs .Value ().([]byte )
303+ if ! ok {
304+ return types .UnsupportedRefValConversionErr (lhs )
305+ }
306+ return types .Bool (bytes .HasSuffix (value , suffix ))
292307 }),
293308 ),
294309 ),
@@ -300,7 +315,11 @@ func (l library) CompileOptions() []cel.EnvOption {
300315 if ! ok {
301316 return types .UnsupportedRefValConversionErr (rhs )
302317 }
303- return types .Bool (strings .HasPrefix (lhs .Value ().(string ), prefix ))
318+ value , ok := lhs .Value ().(string )
319+ if ! ok {
320+ return types .UnsupportedRefValConversionErr (lhs )
321+ }
322+ return types .Bool (strings .HasPrefix (value , prefix ))
304323 }),
305324 ),
306325 cel .MemberOverload ("starts_with_bytes" , []* cel.Type {cel .BytesType , cel .BytesType }, cel .BoolType ,
@@ -309,7 +328,11 @@ func (l library) CompileOptions() []cel.EnvOption {
309328 if ! ok {
310329 return types .UnsupportedRefValConversionErr (rhs )
311330 }
312- return types .Bool (bytes .HasPrefix (lhs .Value ().([]byte ), prefix ))
331+ value , ok := lhs .Value ().([]byte )
332+ if ! ok {
333+ return types .UnsupportedRefValConversionErr (lhs )
334+ }
335+ return types .Bool (bytes .HasPrefix (value , prefix ))
313336 }),
314337 ),
315338 ),
0 commit comments