Skip to content

Commit

Permalink
Fix the nullable check in generated rules (#30)
Browse files Browse the repository at this point in the history
* Use == for null

* Update nullable check
  • Loading branch information
rockwotj authored Nov 22, 2018
1 parent 3dbf0e2 commit 99af1c3
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
2 changes: 1 addition & 1 deletion firebase_rules_generator/generator.cc
Original file line number Diff line number Diff line change
Expand Up @@ -463,7 +463,7 @@ bool RulesGenerator::GenerateField(const protobuf::FieldDescriptor *field,
bool nullable =
(!options.has_nullable() && msg_options.nullable()) || options.nullable();
if (nullable) {
printer.Print(" || resource.$name$ is null", "name", field->json_name());
printer.Print(" || resource.$name$ == null", "name", field->json_name());
}
printer.Print(")");
return true;
Expand Down
4 changes: 2 additions & 2 deletions testdata/testA.rules
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@
function isNullableExampleMessage(resource) {
return resource.keys().hasAll([]) &&
(resource.keys().hasOnly(['bar','foo'])) &&
((!resource.keys().hasAny(['foo'])) || (resource.foo is string) || resource.foo is null) &&
((!resource.keys().hasAny(['foo'])) || (resource.foo is string) || resource.foo == null) &&
((!resource.keys().hasAny(['bar'])) || (resource.bar is string));
}
function isExampleMessage(resource) {
return resource.keys().hasAll([]) &&
(resource.keys().hasOnly(['bar','foo'])) &&
((!resource.keys().hasAny(['foo'])) || (resource.foo is string)) &&
((!resource.keys().hasAny(['bar'])) || (resource.bar is string) || resource.bar is null);
((!resource.keys().hasAny(['bar'])) || (resource.bar is string) || resource.bar == null);
}
// @@END_GENERATED_FUNCTIONS@@

0 comments on commit 99af1c3

Please sign in to comment.