@@ -790,80 +790,19 @@ int InitializeNodeWithArgs(std::vector<std::string>* argv,
790790 V8::SetFlagsFromString (NODE_V8_OPTIONS, sizeof (NODE_V8_OPTIONS) - 1 );
791791#endif
792792
793- std::shared_ptr<EnvironmentOptions> default_env_options =
794- per_process::cli_options->per_isolate ->per_env ;
795- {
796- std::string text;
797- default_env_options->pending_deprecation =
798- credentials::SafeGetenv (" NODE_PENDING_DEPRECATION" , &text) &&
799- text[0 ] == ' 1' ;
800- }
801-
802- // Allow for environment set preserving symlinks.
803- {
804- std::string text;
805- default_env_options->preserve_symlinks =
806- credentials::SafeGetenv (" NODE_PRESERVE_SYMLINKS" , &text) &&
807- text[0 ] == ' 1' ;
808- }
809-
810- {
811- std::string text;
812- default_env_options->preserve_symlinks_main =
813- credentials::SafeGetenv (" NODE_PRESERVE_SYMLINKS_MAIN" , &text) &&
814- text[0 ] == ' 1' ;
815- }
816-
817- if (default_env_options->redirect_warnings .empty ()) {
818- credentials::SafeGetenv (" NODE_REDIRECT_WARNINGS" ,
819- &default_env_options->redirect_warnings );
820- }
793+ HandleEnvOptions (per_process::cli_options->per_isolate ->per_env );
821794
822795#if !defined(NODE_WITHOUT_NODE_OPTIONS)
823796 std::string node_options;
824797
825798 if (credentials::SafeGetenv (" NODE_OPTIONS" , &node_options)) {
826- std::vector<std::string> env_argv;
827- // [0] is expected to be the program name, fill it in from the real argv.
828- env_argv.push_back (argv->at (0 ));
829-
830- bool is_in_string = false ;
831- bool will_start_new_arg = true ;
832- for (std::string::size_type index = 0 ;
833- index < node_options.size ();
834- ++index) {
835- char c = node_options.at (index);
836-
837- // Backslashes escape the following character
838- if (c == ' \\ ' && is_in_string) {
839- if (index + 1 == node_options.size ()) {
840- errors->push_back (" invalid value for NODE_OPTIONS "
841- " (invalid escape)\n " );
842- return 9 ;
843- } else {
844- c = node_options.at (++index);
845- }
846- } else if (c == ' ' && !is_in_string) {
847- will_start_new_arg = true ;
848- continue ;
849- } else if (c == ' "' ) {
850- is_in_string = !is_in_string;
851- continue ;
852- }
799+ std::vector<std::string> env_argv =
800+ ParseNodeOptionsEnvVar (node_options, errors);
853801
854- if (will_start_new_arg) {
855- env_argv.emplace_back (std::string (1 , c));
856- will_start_new_arg = false ;
857- } else {
858- env_argv.back () += c;
859- }
860- }
802+ if (!errors->empty ()) return 9 ;
861803
862- if (is_in_string) {
863- errors->push_back (" invalid value for NODE_OPTIONS "
864- " (unterminated string)\n " );
865- return 9 ;
866- }
804+ // [0] is expected to be the program name, fill it in from the real argv.
805+ env_argv.insert (env_argv.begin (), argv->at (0 ));
867806
868807 const int exit_code = ProcessGlobalArgs (&env_argv,
869808 nullptr ,
0 commit comments