Merge pull request elastic/elasticsearch#4380 from danielmitterdorfer/strict-booleans

This PR removes all leniency in the conversion of Strings to booleans: "true" is converted to the boolean value true, "false" is converted to the boolean value false. Everything else raises an error.

Relates elastic/elasticsearchelastic/elasticsearch#22200

Original commit: elastic/x-pack-elasticsearch@a505df1f5d
This commit is contained in:
Daniel Mitterdorfer 2017-01-19 08:00:06 +01:00 committed by GitHub
commit 6ed83cc8ea
8 changed files with 21 additions and 9 deletions

View File

@ -53,7 +53,7 @@ public class JiraAccount {
try {
URI uri = new URI(url);
Scheme protocol = Scheme.parse(uri.getScheme());
if ((protocol == Scheme.HTTP) && (Booleans.isExplicitTrue(settings.get(ALLOW_HTTP_SETTING)) == false)) {
if ((protocol == Scheme.HTTP) && (Booleans.isTrue(settings.get(ALLOW_HTTP_SETTING)) == false)) {
throw new SettingsException("invalid jira [" + name + "] account settings. unsecure scheme [" + protocol + "]");
}
this.url = uri;

View File

@ -628,11 +628,11 @@ public class Security implements ActionPlugin, IngestPlugin, NetworkPlugin {
String errorMessage = LoggerMessageFormat.format("the [action.auto_create_index] setting value [{}] is too" +
" restrictive. disable [action.auto_create_index] or set it to " +
"[{}{}]", (Object) value, SecurityTemplateService.SECURITY_INDEX_NAME, auditIndex);
if (Booleans.isExplicitFalse(value)) {
if (Booleans.isFalse(value)) {
throw new IllegalArgumentException(errorMessage);
}
if (Booleans.isExplicitTrue(value)) {
if (Booleans.isTrue(value)) {
return;
}

View File

@ -448,11 +448,11 @@ public class Watcher implements ActionPlugin, ScriptPlugin {
String errorMessage = LoggerMessageFormat.format("the [action.auto_create_index] setting value [{}] is too" +
" restrictive. disable [action.auto_create_index] or set it to " +
"[{}, {}, {}*]", (Object) value, Watch.INDEX, TriggeredWatchStore.INDEX_NAME, HistoryStore.INDEX_PREFIX);
if (Booleans.isExplicitFalse(value)) {
if (Booleans.isFalse(value)) {
throw new IllegalArgumentException(errorMessage);
}
if (Booleans.isExplicitTrue(value)) {
if (Booleans.isTrue(value)) {
return;
}

View File

@ -250,6 +250,18 @@ public class WatcherXContentParser implements XContentParser {
return parser.booleanValue();
}
@Override
@SuppressWarnings("deprecated")
public boolean isBooleanValueLenient() throws IOException {
return parser.isBooleanValueLenient();
}
@Override
@SuppressWarnings("deprecated")
public boolean booleanValueLenient() throws IOException {
return parser.booleanValueLenient();
}
@Override
public byte[] binaryValue() throws IOException {
return parser.binaryValue();

View File

@ -10,7 +10,7 @@
"filter" : {
"email" : {
"type" : "pattern_capture",
"preserve_original" : 1,
"preserve_original" : true,
"patterns" : [
"([^@]+)",
"(\\p{L}+)",

View File

@ -116,7 +116,7 @@ public class SettingsFilterTests extends ESTestCase {
}
private String randomBooleanSetting() {
return randomFrom("true", "1", "on", "yes", "false", "0", "off", "no");
return randomFrom("true", "false");
}
private void configureUnfilteredSetting(String settingName, String value) {

View File

@ -9,7 +9,7 @@
"filter" : {
"email" : {
"type" : "pattern_capture",
"preserve_original" : 1,
"preserve_original" : true,
"patterns" : [
"([^@]+)",
"(\\p{L}+)",

View File

@ -9,7 +9,7 @@
"filter" : {
"email" : {
"type" : "pattern_capture",
"preserve_original" : 1,
"preserve_original" : true,
"patterns" : [
"([^@]+)",
"(\\p{L}+)",