From: Nutchanon Wetchasit <Nutchanon.Wetchasit@gmail.com>
Subject: Do not treat getURL()'s undefined and null target parameter as empty string.
Bug: https://savannah.gnu.org/bugs/?50393

See bug #50393 <https://savannah.gnu.org/bugs/?50393>

diff --git a/libcore/vm/ASHandlers.cpp b/libcore/vm/ASHandlers.cpp
index 073bca5..396c97e 100644
--- a/libcore/vm/ASHandlers.cpp
+++ b/libcore/vm/ASHandlers.cpp
@@ -1,7 +1,7 @@
 // ASHandlers.cpp:  ActionScript handlers, for Gnash.
 //
-//   Copyright (C) 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012
-//   Free Software Foundation, Inc
+//   Copyright (C) 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012, 2013, 2014,
+//   2015, 2017 Free Software Foundation, Inc
 //
 // This program is free software; you can redistribute it and/or modify
 // it under the terms of the GNU General Public License as published by
@@ -3520,14 +3520,10 @@ commonGetURL(as_environment& env, as_value target,
         sendVarsMethod = static_cast<MovieClip::VariablesMethod>(method & 3);
     }
 
-    std::string target_string;
-    if (!target.is_undefined() && !target.is_null()) {
-        target_string = target.to_string();
-    }
-
     VM& vm = getVM(env);
     movie_root& m = vm.getRoot();
- 
+    std::string target_string = target.to_string(vm.getSWFVersion());
+
     // If the url starts with "FSCommand:", then this is
     // a message for the host app.
     StringNoCaseEqual noCaseCompare;
diff --git a/testsuite/misc-ming.all/hostcmd_htmltest.sh b/testsuite/misc-ming.all/hostcmd_htmltest.sh
index 0fffffd..cdc5216 100644
--- a/testsuite/misc-ming.all/hostcmd_htmltest.sh
+++ b/testsuite/misc-ming.all/hostcmd_htmltest.sh
@@ -262,11 +262,15 @@ cat << EOF
 		} else if("nullarg" == cmd) {
 			nullarg_call++;
 			check_equals(typeof(arg), "string", "getURL-based FSCommand call with null parameter should pass string-type parameter");
-			xcheck_equals(arg, "null", "getURL-based FSCommand call should pass a correct string representation of null parameter");
+			check_equals(arg, "null", "getURL-based FSCommand call should pass a correct string representation of null parameter");
 		} else if("undefinedarg" == cmd) {
 			undefinedarg_call++;
 			check_equals(typeof(arg), "string", "getURL-based FSCommand call with undefined parameter should pass string-type parameter");
-			xcheck_equals(arg, "undefined", "getURL-based FSCommand call should pass a correct string representation of undefined parameter");
+			if($swfversion >= 7) {
+				check_equals(arg, "undefined", "getURL-based FSCommand call should pass a correct string representation of undefined parameter");
+			} else {
+				check_equals(arg, "", "getURL-based FSCommand call should pass a correct string representation of undefined parameter");
+			}
 		} else if("arrayarg" == cmd) {
 			arrayarg_call++;
 			check_equals(typeof(arg), "string", "getURL-based FSCommand call with array parameter should pass string-type parameter");
diff --git a/testsuite/misc-ming.all/hostcmd_testrunner.sh b/testsuite/misc-ming.all/hostcmd_testrunner.sh
index 6317e04..1946203 100644
--- a/testsuite/misc-ming.all/hostcmd_testrunner.sh
+++ b/testsuite/misc-ming.all/hostcmd_testrunner.sh
@@ -235,11 +235,18 @@ check_equals "\$LINE" '<invoke name="fsCommand" returntype="xml"><arguments><str
 
 # Read for null-parameter FSCommand statement
 read_timeout LINE \$READTIMEOUT <&3
-xcheck_equals "\$LINE" '<invoke name="fsCommand" returntype="xml"><arguments><string>nullarg</string><string>null</string></arguments></invoke>' "Gnash should correctly pass getURL-based FSCommand call with null parameter"
+check_equals "\$LINE" '<invoke name="fsCommand" returntype="xml"><arguments><string>nullarg</string><string>null</string></arguments></invoke>' "Gnash should correctly pass getURL-based FSCommand call with null parameter"
 
-# Read for undefined-parameter FSCommand statement
-read_timeout LINE \$READTIMEOUT <&3
-xcheck_equals "\$LINE" '<invoke name="fsCommand" returntype="xml"><arguments><string>undefinedarg</string><string>undefined</string></arguments></invoke>' "Gnash should correctly pass getURL-based FSCommand call with undefined parameter"
+if [ $swfversion -ge 7 ]
+then
+	# Read for undefined-parameter FSCommand statement (SWF7-above form)
+	read_timeout LINE \$READTIMEOUT <&3
+	check_equals "\$LINE" '<invoke name="fsCommand" returntype="xml"><arguments><string>undefinedarg</string><string>undefined</string></arguments></invoke>' "Gnash should correctly pass getURL-based FSCommand call with undefined parameter"
+else
+	# Read for undefined-parameter FSCommand statement (SWF6-below form)
+	read_timeout LINE \$READTIMEOUT <&3
+	check_equals "\$LINE" '<invoke name="fsCommand" returntype="xml"><arguments><string>undefinedarg</string><string></string></arguments></invoke>' "Gnash should correctly pass getURL-based FSCommand call with undefined parameter"
+fi
 
 # Read for array-parameter FSCommand statement
 read_timeout LINE \$READTIMEOUT <&3
