quoteForCEL takes a formatted, unquoted value and quotes it in a manner suitable for embedding directly in CEL.
(refVal ref.Val, unquotedValue string)
| 187 | // quoteForCEL takes a formatted, unquoted value and quotes it in a manner suitable |
| 188 | // for embedding directly in CEL. |
| 189 | func quoteForCEL(refVal ref.Val, unquotedValue string) string { |
| 190 | switch refVal.Type() { |
| 191 | case types.StringType: |
| 192 | return fmt.Sprintf("%q", unquotedValue) |
| 193 | case types.BytesType: |
| 194 | return fmt.Sprintf("b%q", unquotedValue) |
| 195 | case types.DoubleType: |
| 196 | // special case to handle infinity/NaN |
| 197 | num := refVal.Value().(float64) |
| 198 | if math.IsInf(num, 1) || math.IsInf(num, -1) || math.IsNaN(num) { |
| 199 | return fmt.Sprintf("%q", unquotedValue) |
| 200 | } |
| 201 | return unquotedValue |
| 202 | default: |
| 203 | return unquotedValue |
| 204 | } |
| 205 | } |
| 206 | |
| 207 | // FormatString returns the string representation of a CEL value. |
| 208 | // |
no test coverage detected