Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions conformance/src/test/java/dev/cel/conformance/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -175,8 +175,6 @@ _TESTS_TO_SKIP_PLANNER = [
"timestamps/timestamp_range/sub_time_duration_under",

# Skip until fixed.
"optionals/optionals/map_null_entry_no_such_key",
"optionals/optionals/map_present_key_invalid_field",
"parse/receiver_function_names",
"proto2/extensions_get/package_scoped_test_all_types_ext",
"proto2/extensions_get/package_scoped_repeated_test_all_types",
Expand Down
32 changes: 23 additions & 9 deletions runtime/src/main/java/dev/cel/runtime/planner/StringQualifier.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
package dev.cel.runtime.planner;

import dev.cel.common.exceptions.CelAttributeNotFoundException;
import dev.cel.common.values.OptionalValue;
import dev.cel.common.values.SelectableValue;
import java.util.Map;

Expand All @@ -31,21 +32,34 @@ public String value() {
@Override
@SuppressWarnings("unchecked") // Qualifications on maps/structs must be a string
public Object qualify(Object obj) {
if (obj instanceof OptionalValue) {
OptionalValue<?, ?> opt = (OptionalValue<?, ?>) obj;
if (!opt.isZeroValue()) {
Object inner = opt.value();
if (!(inner instanceof SelectableValue) && !(inner instanceof Map)) {
throw CelAttributeNotFoundException.forFieldResolution(value);
}
}
}

if (obj instanceof SelectableValue) {
return ((SelectableValue<String>) obj).select(value);
} else if (obj instanceof Map) {
Map<String, Object> map = (Map<String, Object>) obj;
if (!map.containsKey(value)) {
throw CelAttributeNotFoundException.forMissingMapKey(value);
}
}

if (obj instanceof Map) {
Map<?, ?> map = (Map<?, ?>) obj;
Object mapVal = map.get(value);

if (mapVal == null) {
throw CelAttributeNotFoundException.of(
String.format("Map value cannot be null for key: %s", value));
if (mapVal != null) {
return mapVal;
}

if (!map.containsKey(value)) {
throw CelAttributeNotFoundException.forMissingMapKey(value);
}
return map.get(value);

throw CelAttributeNotFoundException.of(
String.format("Map value cannot be null for key: %s", value));
}

throw CelAttributeNotFoundException.forFieldResolution(value);
Expand Down
Loading