Skip to content

Commit

Permalink
Strictly verify Hilt compiler flag inputs.
Browse files Browse the repository at this point in the history
RELNOTES=Strictly verify Hilt compiler flag inputs.
PiperOrigin-RevId: 396668785
  • Loading branch information
Chang-Eric authored and Dagger Team committed Sep 14, 2021
1 parent b37be92 commit 742ba95
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
1 change: 1 addition & 0 deletions java/dagger/hilt/processor/internal/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,7 @@ java_library(
srcs = ["HiltCompilerOptions.java"],
deps = [
":processor_errors",
"//java/dagger/internal/guava:base",
"//java/dagger/internal/guava:collect",
"@google_bazel_common//third_party/java/javapoet",
],
Expand Down
19 changes: 17 additions & 2 deletions java/dagger/hilt/processor/internal/HiltCompilerOptions.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

package dagger.hilt.processor.internal;

import com.google.common.base.Ascii;
import com.google.common.collect.ImmutableSet;
import java.util.Arrays;
import java.util.Set;
Expand Down Expand Up @@ -124,8 +125,22 @@ boolean get(ProcessingEnvironment env) {
if (value == null) {
return defaultValue;
}
// TODO(danysantiago): Strictly verify input, either 'true' or 'false' and nothing else.
return Boolean.parseBoolean(value);

// Using Boolean.parseBoolean will turn any non-"true" value into false. Strictly verify the
// inputs to reduce user errors.
String lowercaseValue = Ascii.toLowerCase(value);
switch (lowercaseValue) {
case "true":
return true;
case "false":
return false;
default:
throw new IllegalStateException(
"Expected a value of true/false for the flag \""
+ name
+ "\". Got instead: "
+ value);
}
}

String getQualifiedName() {
Expand Down

0 comments on commit 742ba95

Please sign in to comment.