mirror of
https://github.com/dart-lang/sdk
synced 2024-09-16 00:58:29 +00:00
Fix for issue 27567 (inconsistent handling of invalid -D options
BUG=#27567 R=rmacnak@google.com Review URL: https://codereview.chromium.org/2409263004 .
This commit is contained in:
parent
72503ff98d
commit
aae051e4c3
|
@ -276,32 +276,32 @@ static bool ProcessEnvironmentOption(const char* arg,
|
|||
ASSERT(arg != NULL);
|
||||
if (*arg == '\0') {
|
||||
// Ignore empty -D option.
|
||||
Log::PrintErr("No arguments given to -D option\n");
|
||||
Log::PrintErr("No arguments given to -D option, ignoring it\n");
|
||||
return true;
|
||||
}
|
||||
if (environment == NULL) {
|
||||
environment = new HashMap(&HashMap::SameStringValue, 4);
|
||||
}
|
||||
// Split the name=value part of the -Dname=value argument.
|
||||
const char* equals_pos = strchr(arg, '=');
|
||||
if (equals_pos == NULL) {
|
||||
// No equal sign (name without value) currently not supported.
|
||||
Log::PrintErr("No value given to -D option\n");
|
||||
return false;
|
||||
Log::PrintErr("No value given in -D%s option, ignoring it\n", arg);
|
||||
return true;
|
||||
}
|
||||
|
||||
char* name;
|
||||
char* value = NULL;
|
||||
int name_len = equals_pos - arg;
|
||||
if (name_len == 0) {
|
||||
Log::PrintErr("No name given to -D option\n");
|
||||
return false;
|
||||
Log::PrintErr("No name given in -D%s option, ignoring it\n", arg);
|
||||
return true;
|
||||
}
|
||||
// Split name=value into name and value.
|
||||
name = reinterpret_cast<char*>(malloc(name_len + 1));
|
||||
strncpy(name, arg, name_len);
|
||||
name[name_len] = '\0';
|
||||
value = strdup(equals_pos + 1);
|
||||
if (environment == NULL) {
|
||||
environment = new HashMap(&HashMap::SameStringValue, 4);
|
||||
}
|
||||
HashMap::Entry* entry = environment->Lookup(
|
||||
GetHashmapKeyFromString(name), HashMap::StringHash(name), true);
|
||||
ASSERT(entry != NULL); // Lookup adds an entry if key not found.
|
||||
|
|
10
tests/standalone/env_test.dart
Normal file
10
tests/standalone/env_test.dart
Normal file
|
@ -0,0 +1,10 @@
|
|||
// Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file
|
||||
// for details. All rights reserved. Use of this source code is governed by a
|
||||
// BSD-style license that can be found in the LICENSE file.
|
||||
// SharedOptions=-Dvar -D -D=var -Dvar=invalid -Dvar=valid -Dvar
|
||||
|
||||
import "package:expect/expect.dart";
|
||||
|
||||
main() {
|
||||
Expect.equals('valid', const String.fromEnvironment('var'));
|
||||
}
|
|
@ -25,6 +25,7 @@ packages_file_test: Skip # Uses Platform.executable
|
|||
|
||||
[ ($runtime != vm && $runtime != dart_precompiled && $runtime != dart_app) && ($runtime != drt || $compiler != none)) ]
|
||||
no_assert_test: Fail, OK # This is testing a vm flag.
|
||||
env_test: Skip # This is testing a vm command line parsing scenario.
|
||||
|
||||
[ ($runtime == vm || $runtime == dart_precompiled || $runtime == dart_app) ]
|
||||
package/package_isolate_test: Fail # Issue 12474
|
||||
|
|
Loading…
Reference in a new issue