monotone (1.0-6) 03-url_escaping.diff

Summary

 test/func/attr_mtn_execute/__driver__.lua                      |    4 +-
 test/func/branch_leaves_sync_bug/__driver__.lua                |    9 +++--
 test/func/clone_aborts_on_branch_pattern_in_uri/__driver__.lua |    6 +--
 test/func/clone_branch_no_dir/__driver__.lua                   |   10 ++---
 test/func/clone_creates__MTN_log/__driver__.lua                |    4 +-
 test/func/clone_creates_right__MTN_options/__driver__.lua      |   17 +++++-----
 test/func/clone_validates_target_directory/__driver__.lua      |   12 +++----
 test/func/clone_warning_with_multiple_heads/__driver__.lua     |    4 +-
 test/func/clone_weird_branch_names/__driver__.lua              |    7 ++--
 test/func/imp_test_filesync_confdir/__driver__.lua             |    3 +
 test/func/netsync_over_pipes/__driver__.lua                    |    3 +
 test/func/serve-automate-single-run/__driver__.lua             |    3 +
 test/func/serve-automate/__driver__.lua                        |    3 +
 test/func/util_mtnopt/__driver__.lua                           |    7 +++-
 test/src/testlib.lua                                           |   16 +++++++++
 15 files changed, 69 insertions(+), 39 deletions(-)

    
download this patch

Patch contents

Description: Escape characters in URLs used by test suite.
Bug-Debian: http://bugs.debian.org/668457
Origin: upstream, commit: a0ed177b60caee5cf304c01d83e75812af1225e1
Index: monotone-1.0/test/func/attr_mtn_execute/__driver__.lua
===================================================================
--- monotone-1.0.orig/test/func/attr_mtn_execute/__driver__.lua	2012-04-28 15:41:51.595817578 +0100
+++ monotone-1.0/test/func/attr_mtn_execute/__driver__.lua	2012-04-28 15:43:21.839400322 +0100
@@ -30,7 +30,7 @@
 -- test clone with mtn:execute
 
 copy("test.db", "test-clone.db")
-testURI="file://" .. test.root .. "/test-clone.db?testbranch"
+test_uri="file://" .. url_encode_path(test.root .. "/test-clone.db") .. "?testbranch"
 
-check(nodb_mtn("clone", testURI, "clone"), 0, false, true)
+check(nodb_mtn("clone", test_uri, "clone"), 0, false, true)
 check(indir("clone", {"test", "-x","foo"}, 0, false, false))
Index: monotone-1.0/test/func/branch_leaves_sync_bug/__driver__.lua
===================================================================
--- monotone-1.0.orig/test/func/branch_leaves_sync_bug/__driver__.lua	2012-04-28 15:41:51.595817578 +0100
+++ monotone-1.0/test/func/branch_leaves_sync_bug/__driver__.lua	2012-04-28 15:43:21.839400322 +0100
@@ -46,7 +46,9 @@
 
 -- Create Beth's workspace via checkout, so 'update' works
 chdir(test.root)
-check(abe_mtn("sync", "file://" .. test.root .. "/beth.db?*"), 0, false, false)
+
+test_uri="file://" .. url_encode_path(test.root .. "/beth.db") .. "?*"
+check(abe_mtn("sync", test_uri), 0, false, false)
 check(beth_mtn("checkout", "--branch", "testbranch", "Beth"), 0, false, false)
 chdir("Beth")
 check(beth_mtn("genkey", "beth@test.net"), 0, false, false, string.rep("beth@test.net\n", 2))
@@ -64,7 +66,7 @@
 rev_b = base_revision()
 
 -- Sync dbs
-check(abe_mtn("sync", "file://" .. test.root .. "/beth.db?*"), 0, false, false)
+check(abe_mtn("sync", test_uri), 0, false, false)
 
 -- Abe merges
 chdir("Abe")
@@ -80,7 +82,8 @@
 rev_d = base_revision()
 
 -- Sync dbs (not clear if direction of sync matters)
-check(beth_mtn("sync", "file://" .. test.root .. "/abe.db?*"), 0, false, false)
+test_uri="file://" .. url_encode_path(test.root .. "/abe.db") .. "?*"
+check(beth_mtn("sync", test_uri), 0, false, false)
 
 -- bug; rev_d and rev_c are both heads according to branch_leaves table.
 check(beth_mtn("db", "check"), 0, false, false)
Index: monotone-1.0/test/func/clone_aborts_on_branch_pattern_in_uri/__driver__.lua
===================================================================
--- monotone-1.0.orig/test/func/clone_aborts_on_branch_pattern_in_uri/__driver__.lua	2012-04-28 15:41:51.595817578 +0100
+++ monotone-1.0/test/func/clone_aborts_on_branch_pattern_in_uri/__driver__.lua	2012-04-28 15:43:21.839400322 +0100
@@ -6,9 +6,9 @@
 commit("mybranch")
 
 copy("test.db", "test-clone.db")
-testURI="file://" .. test.root .. "/test-clone.db?mybranch*"
 
-check(nodb_mtn("clone", testURI), 1, false, true)
+test_uri="file://" .. url_encode_path(test.root .. "/test-clone.db") .. "?mybranch*"
+check(nodb_mtn("clone", test_uri), 1, false, true)
 check(qgrep("you must specify an unambiguous branch to clone", "stderr"))
 
 -- the branch option is invalid in non-URI mode
@@ -16,7 +16,7 @@
 check(qgrep("the '--branch' option is only valid with an URI to clone", "stderr"))
 
 -- finally, this should succeed
-check(nodb_mtn("clone", testURI, "--branch=mybranch"), 0, false, false)
+check(nodb_mtn("clone", test_uri, "--branch=mybranch"), 0, false, false)
 check(exists("mybranch"))
 check(readfile("foo") == readfile("mybranch/foo"))
 
Index: monotone-1.0/test/func/clone_branch_no_dir/__driver__.lua
===================================================================
--- monotone-1.0.orig/test/func/clone_branch_no_dir/__driver__.lua	2012-04-28 15:41:51.595817578 +0100
+++ monotone-1.0/test/func/clone_branch_no_dir/__driver__.lua	2012-04-28 15:43:21.839400322 +0100
@@ -6,18 +6,18 @@
 commit("mybranch")
 
 copy("test.db", "test-clone.db")
-testURI="file://" .. test.root .. "/test-clone.db?mybranch"
 
-check(nodb_mtn("clone", testURI), 0, false, false)
+test_uri="file://" .. url_encode_path(test.root .. "/test-clone.db") .. "?mybranch"
+check(nodb_mtn("clone", test_uri), 0, false, false)
 check(exists("mybranch"))
 check(readfile("foo") == readfile("mybranch/foo"))
 
 -- but now that that directory exists, this clone should fail
-check(nodb_mtn("clone", testURI), 1, false, false)
+check(nodb_mtn("clone", test_uri), 1, false, false)
 
 -- but succeed if given a specific dir
-check(nodb_mtn("clone", testURI, "otherdir"), 0, false, false)
+check(nodb_mtn("clone", test_uri, "otherdir"), 0, false, false)
 
 -- clone into . should not fail, like checkout
 mkdir("test4")
-check(indir("test4", nodb_mtn("clone", testURI, ".")), 0, false, false)
+check(indir("test4", nodb_mtn("clone", test_uri, ".")), 0, false, false)
Index: monotone-1.0/test/func/clone_creates__MTN_log/__driver__.lua
===================================================================
--- monotone-1.0.orig/test/func/clone_creates__MTN_log/__driver__.lua	2012-04-28 15:41:51.595817578 +0100
+++ monotone-1.0/test/func/clone_creates__MTN_log/__driver__.lua	2012-04-28 15:43:21.840400284 +0100
@@ -13,9 +13,9 @@
 check(mtn("--branch=testbranch", "--rcfile=commit_log.lua", "commit"), 0, false, false)
 
 copy("test.db", "test-clone.db")
-testURI="file://" .. test.root .. "/test-clone.db?testbranch"
 
-check(nodb_mtn("clone", testURI, "testbranch"), 0, false, true)
+test_uri="file://" .. url_encode_path(test.root .. "/test-clone.db") .. "?testbranch"
+check(nodb_mtn("clone", test_uri, "testbranch"), 0, false, true)
 
 check(exists("testbranch/_MTN/log"))
 check(fsize("_MTN/log") == 0)
Index: monotone-1.0/test/func/clone_creates_right__MTN_options/__driver__.lua
===================================================================
--- monotone-1.0.orig/test/func/clone_creates_right__MTN_options/__driver__.lua	2012-04-28 15:41:51.595817578 +0100
+++ monotone-1.0/test/func/clone_creates_right__MTN_options/__driver__.lua	2012-04-28 15:43:21.840400284 +0100
@@ -10,7 +10,7 @@
 writefile("testfile", "blah")
 commit()
 
-testURI="file://" .. test.root .. "/test-clone.db?testbranch"
+test_uri="file://" .. url_encode_path(test.root .. "/test-clone.db") .. "?testbranch"
 
 -- We use RAW_MTN because it used to be that passing --db= (as
 -- MTN does) would hide a bug in this functionality...
@@ -18,16 +18,17 @@
 -- all of these inherit options settings from the current _MTN dir
 -- unless they override them on the command line
 
-check(nodb_mtn("clone", testURI, "test_dir1"), 0, false, false)
-check(nodb_mtn("clone", "--revision", rev, testURI, "test_dir2"), 0, false, false)
-check(nodb_mtn("--db=" .. test.root .. "/test-new.db", "clone", testURI, "test_dir3"), 0, false, false)
-check(nodb_mtn("--db=" .. test.root .. "/test-new.db", "clone", testURI, "--revision", rev, "test_dir4"), 0, false, false)
+check(nodb_mtn("clone", test_uri, "test_dir1"), 0, false, false)
+check(nodb_mtn("clone", "--revision", rev, test_uri, "test_dir2"), 0, false, false)
+check(nodb_mtn("--db=" .. test.root .. "/test-new.db", "clone", test_uri, "test_dir3"), 0, false, false)
+check(nodb_mtn("--db=" .. test.root .. "/test-new.db", "clone", test_uri, "--revision", rev, "test_dir4"), 0, false, false)
 
 -- checkout fails if the specified revision is not a member of the specified branch
-testURI="file://" .. test.root .. "/test-clone.db?foobar"
-check(nodb_mtn("clone", testURI, "--revision", rev, "test_dir5"), 1, false, false)
+test_uri="file://" .. url_encode_path(test.root .. "/test-clone.db") .. "?foobar"
+
+check(nodb_mtn("clone", test_uri, "--revision", rev, "test_dir5"), 1, false, false)
 check(nodb_mtn("cert", rev, "branch", "foobar", "-d", "test-clone.db"), 0, false, false)
-check(nodb_mtn("clone", testURI, "--revision", rev, "test_dir6"), 0, false, false)
+check(nodb_mtn("clone", test_uri, "--revision", rev, "test_dir6"), 0, false, false)
 
 
 for i = 1,2 do
Index: monotone-1.0/test/func/clone_validates_target_directory/__driver__.lua
===================================================================
--- monotone-1.0.orig/test/func/clone_validates_target_directory/__driver__.lua	2012-04-28 15:41:51.595817578 +0100
+++ monotone-1.0/test/func/clone_validates_target_directory/__driver__.lua	2012-04-28 15:43:21.840400284 +0100
@@ -6,15 +6,15 @@
 commit()
 
 copy("test.db", "test-clone.db")
-testURI="file://" .. test.root .. "/test-clone.db?testbranch"
 
-check(nodb_mtn("clone", testURI, "test_dir1"), 0, false, false)
+test_uri="file://" .. url_encode_path(test.root .. "/test-clone.db") .. "?testbranch"
+check(nodb_mtn("clone", test_uri, "test_dir1"), 0, false, false)
 
 writefile("test_dir2")
-check(nodb_mtn("clone", testURI, "test_dir2"), 1, false, false)
+check(nodb_mtn("clone", test_uri, "test_dir2"), 1, false, false)
 
 mkdir("test_dir3")
-check(nodb_mtn("clone", testURI, "test_dir3"), 1, false, false)
+check(nodb_mtn("clone", test_uri, "test_dir3"), 1, false, false)
 
 if existsonpath("chmod") and existsonpath("test") then
   -- skip this part if run as root (hi Gentoo!)
@@ -27,9 +27,9 @@
   else
     mkdir("test_dir4")
     check({"chmod", "444", "test_dir4"}, 0, false)
-    check(nodb_mtn("clone", testURI, "test_dir4"),
+    check(nodb_mtn("clone", test_uri, "test_dir4"),
              1, false, false)
-    check(nodb_mtn("clone", testURI, "test_dir4/subdir"),
+    check(nodb_mtn("clone", test_uri, "test_dir4/subdir"),
              1, false, false)
     -- Reset the permissions so Autotest can correctly clean up our
     -- temporary directory.
Index: monotone-1.0/test/func/clone_warning_with_multiple_heads/__driver__.lua
===================================================================
--- monotone-1.0.orig/test/func/clone_warning_with_multiple_heads/__driver__.lua	2012-04-28 15:41:51.595817578 +0100
+++ monotone-1.0/test/func/clone_warning_with_multiple_heads/__driver__.lua	2012-04-28 15:43:21.840400284 +0100
@@ -16,9 +16,9 @@
 REV3=base_revision()
 
 copy("test.db", "test-clone.db")
-testURI="file://" .. test.root .. "/test-clone.db?testbranch"
 
-check(nodb_mtn("clone", testURI, "test_dirA"),
+test_uri="file://" .. url_encode_path(test.root .. "/test-clone.db") .. "?testbranch"
+check(nodb_mtn("clone", test_uri, "test_dirA"),
          1, false, true)
 check(qgrep(REV2, "stderr"))
 check(qgrep(REV3, "stderr"))
Index: monotone-1.0/test/func/clone_weird_branch_names/__driver__.lua
===================================================================
--- monotone-1.0.orig/test/func/clone_weird_branch_names/__driver__.lua	2012-04-28 15:41:51.595817578 +0100
+++ monotone-1.0/test/func/clone_weird_branch_names/__driver__.lua	2012-04-28 15:43:21.840400284 +0100
@@ -6,10 +6,11 @@
 commit("my-branch[1,2]-1^3")
 
 copy("test.db", "test-clone.db")
--- some of the special chars need to get double-escaped to get "through"
-testURI="file://" .. test.root .. "/test-clone.db?my-branch\\\[1,2\\\]-1^3"
 
-check(nodb_mtn("clone", testURI), 0, false, false)
+-- some of the special chars need to get double-escaped to get "through"
+test_uri="file://" .. url_encode_path(test.root .. "/test-clone.db") ..
+  "?" .. url_encode_query("my-branch\\\[1,2\\\]-1^3")
+check(nodb_mtn("clone", test_uri), 0, false, false)
 check(exists("my-branch[1,2]-1^3"))
 check(readfile("foo") == readfile("my-branch[1,2]-1^3/foo"))
 
Index: monotone-1.0/test/func/imp_test_filesync_confdir/__driver__.lua
===================================================================
--- monotone-1.0.orig/test/func/imp_test_filesync_confdir/__driver__.lua	2012-04-28 15:41:51.595817578 +0100
+++ monotone-1.0/test/func/imp_test_filesync_confdir/__driver__.lua	2012-04-28 15:43:21.840400284 +0100
@@ -18,7 +18,8 @@
    rcfile:close()
 end
 
-check(mtn("sync", "file://" .. test.root .. "/test2.db?testbranch"), 0, true, false)
+test_uri="file://" .. url_encode_path(test.root .. "/test2.db") .. "?testbranch"
+check(mtn("sync", test_uri), 0, true, false)
 
 n = 0
 
Index: monotone-1.0/test/func/netsync_over_pipes/__driver__.lua
===================================================================
--- monotone-1.0.orig/test/func/netsync_over_pipes/__driver__.lua	2012-04-28 15:41:51.595817578 +0100
+++ monotone-1.0/test/func/netsync_over_pipes/__driver__.lua	2012-04-28 15:43:21.840400284 +0100
@@ -7,6 +7,7 @@
 addfile("testfile", "foo")
 commit()
 
-check(mtn("sync", "file://" .. test.root .. "/test2.db?testbranch"), 0, false, true)
+test_uri="file://" .. url_encode_path(test.root .. "/test2.db") .. "?testbranch"
+check(mtn("sync", test_uri), 0, false, true)
 check(not qgrep("error", "stderr"))
 check_same_db_contents("test.db", "test2.db")
Index: monotone-1.0/test/func/serve-automate-single-run/__driver__.lua
===================================================================
--- monotone-1.0.orig/test/func/serve-automate-single-run/__driver__.lua	2012-04-28 15:41:51.595817578 +0100
+++ monotone-1.0/test/func/serve-automate-single-run/__driver__.lua	2012-04-28 15:43:21.840400284 +0100
@@ -60,8 +60,9 @@
 -- 'file:' not supported on Windows
 
 copy("allow-automate.lua", "custom_test_hooks.lua")
+test_uri="file://" .. url_encode_path(test.root .. "/test.db")
 check(mtn2("automate", "remote", "--remote-stdio-host",
-	   "file://"..test.root.."/test.db",
+	   test_uri,
 	   "get_file_of", "--", "-r".. R1, "foo"), 0, true, false)
 check(qgrep("bar", "stdout"))
 end
Index: monotone-1.0/test/func/serve-automate/__driver__.lua
===================================================================
--- monotone-1.0.orig/test/func/serve-automate/__driver__.lua	2012-04-28 15:41:51.595817578 +0100
+++ monotone-1.0/test/func/serve-automate/__driver__.lua	2012-04-28 15:43:21.840400284 +0100
@@ -56,7 +56,8 @@
 if ostype ~= "Windows" then
 -- 'file:' not supported on Windows
 
-check(mtn2("automate", "remote_stdio", "file://" .. test.root .. "/test.db"),
+test_uri="file://" .. url_encode_path(test.root .. "/test.db")
+check(mtn2("automate", "remote_stdio", test_uri),
       0, true, false, "l17:interface_versione")
 check(parse_stdio(readfile("stdout"), 0, 0, "m") ~= nil)
 end
Index: monotone-1.0/test/func/util_mtnopt/__driver__.lua
===================================================================
--- monotone-1.0.orig/test/func/util_mtnopt/__driver__.lua	2012-04-28 15:41:51.595817578 +0100
+++ monotone-1.0/test/func/util_mtnopt/__driver__.lua	2012-04-28 15:43:21.840400284 +0100
@@ -6,6 +6,11 @@
 
 normalized_testroot = normalize_path (test.root)
 
+-- Escape regexp special characters to form a proper regexp that correctly
+-- checks for the given path.
+escaped_testroot = string.gsub(normalized_testroot, "([*+.()[\\^$|?])",
+  function (x) return "\\" .. x end)
+
 -- check default operation
 
 -- MinGW does not process the shebang in mtnopt; must invoke sh directly
@@ -13,7 +18,7 @@
 -- Don't pass the full /bin/sh path, it looks like that doesn't always
 -- work under mingw.
 check({"sh", "./mtnopt"}, 0, true)
-check(qgrep('^MTN_database="' .. normalized_testroot .. '/test.db";$', "stdout"))
+check(qgrep('^MTN_database="' .. escaped_testroot .. '/test.db";$', "stdout"))
 check(qgrep('^MTN_branch="testbranch";$', "stdout"))
 
 -- check operation with a specific key and just returning the value
Index: monotone-1.0/test/src/testlib.lua
===================================================================
--- monotone-1.0.orig/test/src/testlib.lua	2012-04-28 15:41:51.595817578 +0100
+++ monotone-1.0/test/src/testlib.lua	2012-04-28 15:43:21.841400246 +0100
@@ -144,6 +144,22 @@
   return n
 end
 
+-- encodes a query by percent escaping reserved characters (as defined
+-- in RFC 3986) - except for the directory separator ('/').
+function url_encode_path(path)
+  path = string.gsub(path, "([!*'();:@&=+$,?#[%]])",
+    function (x) return string.format("%%%02X", string.byte(x)) end)
+  return string.gsub(path, " ", "+")
+end
+
+-- encodes a query by percent escaping reserved characters (as defined
+-- in RFC 3986) - except for the ampersand and equal sign ('&', '=')
+function url_encode_query(path)
+  path = string.gsub(path, "([!*'();:@+$,/?#[%]])",
+    function (x) return string.format("%%%02X", string.byte(x)) end)
+  return string.gsub(path, " ", "+")
+end
+
 function open_or_err(filename, mode, depth)
   local file, e = io.open(filename, mode)
   if file == nil then