PageRenderTime 79ms CodeModel.GetById 21ms RepoModel.GetById 0ms app.codeStats 0ms

/monotone/03-url_escaping.diff

https://bitbucket.org/kaendfinger/aur-mirror
diff | 337 lines | 290 code | 47 blank | 0 comment | 0 complexity | d6b60f3b0adecc158dc942045d04bcf6 MD5 | raw file
Possible License(s): LGPL-2.0, Unlicense, AGPL-1.0, BitTorrent-1.0, EPL-1.0, GPL-3.0, BSD-3-Clause, GPL-2.0, MIT, CC-BY-SA-3.0, BSD-2-Clause, MPL-2.0, BSD-3-Clause-No-Nuclear-License-2014, JSON, AGPL-3.0, MPL-2.0-no-copyleft-exception, IPL-1.0, LGPL-2.1, ISC, CC-BY-3.0, WTFPL, 0BSD, CC0-1.0, LGPL-3.0, Cube, Apache-2.0
  1. Description: Escape characters in URLs used by test suite.
  2. Bug-Debian: http://bugs.debian.org/668457
  3. Origin: upstream, commit: a0ed177b60caee5cf304c01d83e75812af1225e1
  4. Index: monotone-1.0/test/func/attr_mtn_execute/__driver__.lua
  5. ===================================================================
  6. --- test/func/attr_mtn_execute/__driver__.lua 2012-04-28 15:41:51.595817578 +0100
  7. +++ test/func/attr_mtn_execute/__driver__.lua 2012-04-28 15:43:21.839400322 +0100
  8. @@ -30,7 +30,7 @@
  9. -- test clone with mtn:execute
  10. copy("test.db", "test-clone.db")
  11. -testURI="file://" .. test.root .. "/test-clone.db?testbranch"
  12. +test_uri="file://" .. url_encode_path(test.root .. "/test-clone.db") .. "?testbranch"
  13. -check(nodb_mtn("clone", testURI, "clone"), 0, false, true)
  14. +check(nodb_mtn("clone", test_uri, "clone"), 0, false, true)
  15. check(indir("clone", {"test", "-x","foo"}, 0, false, false))
  16. Index: monotone-1.0/test/func/branch_leaves_sync_bug/__driver__.lua
  17. ===================================================================
  18. --- test/func/branch_leaves_sync_bug/__driver__.lua 2012-04-28 15:41:51.595817578 +0100
  19. +++ test/func/branch_leaves_sync_bug/__driver__.lua 2012-04-28 15:43:21.839400322 +0100
  20. @@ -46,7 +46,9 @@
  21. -- Create Beth's workspace via checkout, so 'update' works
  22. chdir(test.root)
  23. -check(abe_mtn("sync", "file://" .. test.root .. "/beth.db?*"), 0, false, false)
  24. +
  25. +test_uri="file://" .. url_encode_path(test.root .. "/beth.db") .. "?*"
  26. +check(abe_mtn("sync", test_uri), 0, false, false)
  27. check(beth_mtn("checkout", "--branch", "testbranch", "Beth"), 0, false, false)
  28. chdir("Beth")
  29. check(beth_mtn("genkey", "beth@test.net"), 0, false, false, string.rep("beth@test.net\n", 2))
  30. @@ -64,7 +66,7 @@
  31. rev_b = base_revision()
  32. -- Sync dbs
  33. -check(abe_mtn("sync", "file://" .. test.root .. "/beth.db?*"), 0, false, false)
  34. +check(abe_mtn("sync", test_uri), 0, false, false)
  35. -- Abe merges
  36. chdir("Abe")
  37. @@ -80,7 +82,8 @@
  38. rev_d = base_revision()
  39. -- Sync dbs (not clear if direction of sync matters)
  40. -check(beth_mtn("sync", "file://" .. test.root .. "/abe.db?*"), 0, false, false)
  41. +test_uri="file://" .. url_encode_path(test.root .. "/abe.db") .. "?*"
  42. +check(beth_mtn("sync", test_uri), 0, false, false)
  43. -- bug; rev_d and rev_c are both heads according to branch_leaves table.
  44. check(beth_mtn("db", "check"), 0, false, false)
  45. Index: monotone-1.0/test/func/clone_aborts_on_branch_pattern_in_uri/__driver__.lua
  46. ===================================================================
  47. --- test/func/clone_aborts_on_branch_pattern_in_uri/__driver__.lua 2012-04-28 15:41:51.595817578 +0100
  48. +++ test/func/clone_aborts_on_branch_pattern_in_uri/__driver__.lua 2012-04-28 15:43:21.839400322 +0100
  49. @@ -6,9 +6,9 @@
  50. commit("mybranch")
  51. copy("test.db", "test-clone.db")
  52. -testURI="file://" .. test.root .. "/test-clone.db?mybranch*"
  53. -check(nodb_mtn("clone", testURI), 1, false, true)
  54. +test_uri="file://" .. url_encode_path(test.root .. "/test-clone.db") .. "?mybranch*"
  55. +check(nodb_mtn("clone", test_uri), 1, false, true)
  56. check(qgrep("you must specify an unambiguous branch to clone", "stderr"))
  57. -- the branch option is invalid in non-URI mode
  58. @@ -16,7 +16,7 @@
  59. check(qgrep("the '--branch' option is only valid with an URI to clone", "stderr"))
  60. -- finally, this should succeed
  61. -check(nodb_mtn("clone", testURI, "--branch=mybranch"), 0, false, false)
  62. +check(nodb_mtn("clone", test_uri, "--branch=mybranch"), 0, false, false)
  63. check(exists("mybranch"))
  64. check(readfile("foo") == readfile("mybranch/foo"))
  65. Index: monotone-1.0/test/func/clone_branch_no_dir/__driver__.lua
  66. ===================================================================
  67. --- test/func/clone_branch_no_dir/__driver__.lua 2012-04-28 15:41:51.595817578 +0100
  68. +++ test/func/clone_branch_no_dir/__driver__.lua 2012-04-28 15:43:21.839400322 +0100
  69. @@ -6,18 +6,18 @@
  70. commit("mybranch")
  71. copy("test.db", "test-clone.db")
  72. -testURI="file://" .. test.root .. "/test-clone.db?mybranch"
  73. -check(nodb_mtn("clone", testURI), 0, false, false)
  74. +test_uri="file://" .. url_encode_path(test.root .. "/test-clone.db") .. "?mybranch"
  75. +check(nodb_mtn("clone", test_uri), 0, false, false)
  76. check(exists("mybranch"))
  77. check(readfile("foo") == readfile("mybranch/foo"))
  78. -- but now that that directory exists, this clone should fail
  79. -check(nodb_mtn("clone", testURI), 1, false, false)
  80. +check(nodb_mtn("clone", test_uri), 1, false, false)
  81. -- but succeed if given a specific dir
  82. -check(nodb_mtn("clone", testURI, "otherdir"), 0, false, false)
  83. +check(nodb_mtn("clone", test_uri, "otherdir"), 0, false, false)
  84. -- clone into . should not fail, like checkout
  85. mkdir("test4")
  86. -check(indir("test4", nodb_mtn("clone", testURI, ".")), 0, false, false)
  87. +check(indir("test4", nodb_mtn("clone", test_uri, ".")), 0, false, false)
  88. Index: monotone-1.0/test/func/clone_creates__MTN_log/__driver__.lua
  89. ===================================================================
  90. --- test/func/clone_creates__MTN_log/__driver__.lua 2012-04-28 15:41:51.595817578 +0100
  91. +++ test/func/clone_creates__MTN_log/__driver__.lua 2012-04-28 15:43:21.840400284 +0100
  92. @@ -13,9 +13,9 @@
  93. check(mtn("--branch=testbranch", "--rcfile=commit_log.lua", "commit"), 0, false, false)
  94. copy("test.db", "test-clone.db")
  95. -testURI="file://" .. test.root .. "/test-clone.db?testbranch"
  96. -check(nodb_mtn("clone", testURI, "testbranch"), 0, false, true)
  97. +test_uri="file://" .. url_encode_path(test.root .. "/test-clone.db") .. "?testbranch"
  98. +check(nodb_mtn("clone", test_uri, "testbranch"), 0, false, true)
  99. check(exists("testbranch/_MTN/log"))
  100. check(fsize("_MTN/log") == 0)
  101. Index: monotone-1.0/test/func/clone_creates_right__MTN_options/__driver__.lua
  102. ===================================================================
  103. --- test/func/clone_creates_right__MTN_options/__driver__.lua 2012-04-28 15:41:51.595817578 +0100
  104. +++ test/func/clone_creates_right__MTN_options/__driver__.lua 2012-04-28 15:43:21.840400284 +0100
  105. @@ -10,7 +10,7 @@
  106. writefile("testfile", "blah")
  107. commit()
  108. -testURI="file://" .. test.root .. "/test-clone.db?testbranch"
  109. +test_uri="file://" .. url_encode_path(test.root .. "/test-clone.db") .. "?testbranch"
  110. -- We use RAW_MTN because it used to be that passing --db= (as
  111. -- MTN does) would hide a bug in this functionality...
  112. @@ -18,16 +18,17 @@
  113. -- all of these inherit options settings from the current _MTN dir
  114. -- unless they override them on the command line
  115. -check(nodb_mtn("clone", testURI, "test_dir1"), 0, false, false)
  116. -check(nodb_mtn("clone", "--revision", rev, testURI, "test_dir2"), 0, false, false)
  117. -check(nodb_mtn("--db=" .. test.root .. "/test-new.db", "clone", testURI, "test_dir3"), 0, false, false)
  118. -check(nodb_mtn("--db=" .. test.root .. "/test-new.db", "clone", testURI, "--revision", rev, "test_dir4"), 0, false, false)
  119. +check(nodb_mtn("clone", test_uri, "test_dir1"), 0, false, false)
  120. +check(nodb_mtn("clone", "--revision", rev, test_uri, "test_dir2"), 0, false, false)
  121. +check(nodb_mtn("--db=" .. test.root .. "/test-new.db", "clone", test_uri, "test_dir3"), 0, false, false)
  122. +check(nodb_mtn("--db=" .. test.root .. "/test-new.db", "clone", test_uri, "--revision", rev, "test_dir4"), 0, false, false)
  123. -- checkout fails if the specified revision is not a member of the specified branch
  124. -testURI="file://" .. test.root .. "/test-clone.db?foobar"
  125. -check(nodb_mtn("clone", testURI, "--revision", rev, "test_dir5"), 1, false, false)
  126. +test_uri="file://" .. url_encode_path(test.root .. "/test-clone.db") .. "?foobar"
  127. +
  128. +check(nodb_mtn("clone", test_uri, "--revision", rev, "test_dir5"), 1, false, false)
  129. check(nodb_mtn("cert", rev, "branch", "foobar", "-d", "test-clone.db"), 0, false, false)
  130. -check(nodb_mtn("clone", testURI, "--revision", rev, "test_dir6"), 0, false, false)
  131. +check(nodb_mtn("clone", test_uri, "--revision", rev, "test_dir6"), 0, false, false)
  132. for i = 1,2 do
  133. Index: monotone-1.0/test/func/clone_validates_target_directory/__driver__.lua
  134. ===================================================================
  135. --- test/func/clone_validates_target_directory/__driver__.lua 2012-04-28 15:41:51.595817578 +0100
  136. +++ test/func/clone_validates_target_directory/__driver__.lua 2012-04-28 15:43:21.840400284 +0100
  137. @@ -6,15 +6,15 @@
  138. commit()
  139. copy("test.db", "test-clone.db")
  140. -testURI="file://" .. test.root .. "/test-clone.db?testbranch"
  141. -check(nodb_mtn("clone", testURI, "test_dir1"), 0, false, false)
  142. +test_uri="file://" .. url_encode_path(test.root .. "/test-clone.db") .. "?testbranch"
  143. +check(nodb_mtn("clone", test_uri, "test_dir1"), 0, false, false)
  144. writefile("test_dir2")
  145. -check(nodb_mtn("clone", testURI, "test_dir2"), 1, false, false)
  146. +check(nodb_mtn("clone", test_uri, "test_dir2"), 1, false, false)
  147. mkdir("test_dir3")
  148. -check(nodb_mtn("clone", testURI, "test_dir3"), 1, false, false)
  149. +check(nodb_mtn("clone", test_uri, "test_dir3"), 1, false, false)
  150. if existsonpath("chmod") and existsonpath("test") then
  151. -- skip this part if run as root (hi Gentoo!)
  152. @@ -27,9 +27,9 @@
  153. else
  154. mkdir("test_dir4")
  155. check({"chmod", "444", "test_dir4"}, 0, false)
  156. - check(nodb_mtn("clone", testURI, "test_dir4"),
  157. + check(nodb_mtn("clone", test_uri, "test_dir4"),
  158. 1, false, false)
  159. - check(nodb_mtn("clone", testURI, "test_dir4/subdir"),
  160. + check(nodb_mtn("clone", test_uri, "test_dir4/subdir"),
  161. 1, false, false)
  162. -- Reset the permissions so Autotest can correctly clean up our
  163. -- temporary directory.
  164. Index: monotone-1.0/test/func/clone_warning_with_multiple_heads/__driver__.lua
  165. ===================================================================
  166. --- test/func/clone_warning_with_multiple_heads/__driver__.lua 2012-04-28 15:41:51.595817578 +0100
  167. +++ monotone-1.0/test/func/clone_warning_with_multiple_heads/__driver__.lua 2012-04-28 15:43:21.840400284 +0100
  168. @@ -16,9 +16,9 @@
  169. REV3=base_revision()
  170. copy("test.db", "test-clone.db")
  171. -testURI="file://" .. test.root .. "/test-clone.db?testbranch"
  172. -check(nodb_mtn("clone", testURI, "test_dirA"),
  173. +test_uri="file://" .. url_encode_path(test.root .. "/test-clone.db") .. "?testbranch"
  174. +check(nodb_mtn("clone", test_uri, "test_dirA"),
  175. 1, false, true)
  176. check(qgrep(REV2, "stderr"))
  177. check(qgrep(REV3, "stderr"))
  178. Index: monotone-1.0/test/func/clone_weird_branch_names/__driver__.lua
  179. ===================================================================
  180. --- test/func/clone_weird_branch_names/__driver__.lua 2012-04-28 15:41:51.595817578 +0100
  181. +++ test/func/clone_weird_branch_names/__driver__.lua 2012-04-28 15:43:21.840400284 +0100
  182. @@ -6,10 +6,11 @@
  183. commit("my-branch[1,2]-1^3")
  184. copy("test.db", "test-clone.db")
  185. --- some of the special chars need to get double-escaped to get "through"
  186. -testURI="file://" .. test.root .. "/test-clone.db?my-branch\\\[1,2\\\]-1^3"
  187. -check(nodb_mtn("clone", testURI), 0, false, false)
  188. +-- some of the special chars need to get double-escaped to get "through"
  189. +test_uri="file://" .. url_encode_path(test.root .. "/test-clone.db") ..
  190. + "?" .. url_encode_query("my-branch\\\[1,2\\\]-1^3")
  191. +check(nodb_mtn("clone", test_uri), 0, false, false)
  192. check(exists("my-branch[1,2]-1^3"))
  193. check(readfile("foo") == readfile("my-branch[1,2]-1^3/foo"))
  194. Index: monotone-1.0/test/func/imp_test_filesync_confdir/__driver__.lua
  195. ===================================================================
  196. --- test/func/imp_test_filesync_confdir/__driver__.lua 2012-04-28 15:41:51.595817578 +0100
  197. +++ test/func/imp_test_filesync_confdir/__driver__.lua 2012-04-28 15:43:21.840400284 +0100
  198. @@ -18,7 +18,8 @@
  199. rcfile:close()
  200. end
  201. -check(mtn("sync", "file://" .. test.root .. "/test2.db?testbranch"), 0, true, false)
  202. +test_uri="file://" .. url_encode_path(test.root .. "/test2.db") .. "?testbranch"
  203. +check(mtn("sync", test_uri), 0, true, false)
  204. n = 0
  205. Index: monotone-1.0/test/func/netsync_over_pipes/__driver__.lua
  206. ===================================================================
  207. --- test/func/netsync_over_pipes/__driver__.lua 2012-04-28 15:41:51.595817578 +0100
  208. +++ test/func/netsync_over_pipes/__driver__.lua 2012-04-28 15:43:21.840400284 +0100
  209. @@ -7,6 +7,7 @@
  210. addfile("testfile", "foo")
  211. commit()
  212. -check(mtn("sync", "file://" .. test.root .. "/test2.db?testbranch"), 0, false, true)
  213. +test_uri="file://" .. url_encode_path(test.root .. "/test2.db") .. "?testbranch"
  214. +check(mtn("sync", test_uri), 0, false, true)
  215. check(not qgrep("error", "stderr"))
  216. check_same_db_contents("test.db", "test2.db")
  217. Index: monotone-1.0/test/func/serve-automate-single-run/__driver__.lua
  218. ===================================================================
  219. --- test/func/serve-automate-single-run/__driver__.lua 2012-04-28 15:41:51.595817578 +0100
  220. +++ test/func/serve-automate-single-run/__driver__.lua 2012-04-28 15:43:21.840400284 +0100
  221. @@ -60,8 +60,9 @@
  222. -- 'file:' not supported on Windows
  223. copy("allow-automate.lua", "custom_test_hooks.lua")
  224. +test_uri="file://" .. url_encode_path(test.root .. "/test.db")
  225. check(mtn2("automate", "remote", "--remote-stdio-host",
  226. - "file://"..test.root.."/test.db",
  227. + test_uri,
  228. "get_file_of", "--", "-r".. R1, "foo"), 0, true, false)
  229. check(qgrep("bar", "stdout"))
  230. end
  231. Index: monotone-1.0/test/func/serve-automate/__driver__.lua
  232. ===================================================================
  233. --- test/func/serve-automate/__driver__.lua 2012-04-28 15:41:51.595817578 +0100
  234. +++ test/func/serve-automate/__driver__.lua 2012-04-28 15:43:21.840400284 +0100
  235. @@ -56,7 +56,8 @@
  236. if ostype ~= "Windows" then
  237. -- 'file:' not supported on Windows
  238. -check(mtn2("automate", "remote_stdio", "file://" .. test.root .. "/test.db"),
  239. +test_uri="file://" .. url_encode_path(test.root .. "/test.db")
  240. +check(mtn2("automate", "remote_stdio", test_uri),
  241. 0, true, false, "l17:interface_versione")
  242. check(parse_stdio(readfile("stdout"), 0, 0, "m") ~= nil)
  243. end
  244. Index: monotone-1.0/test/func/util_mtnopt/__driver__.lua
  245. ===================================================================
  246. --- test/func/util_mtnopt/__driver__.lua 2012-04-28 15:41:51.595817578 +0100
  247. +++ test/func/util_mtnopt/__driver__.lua 2012-04-28 15:43:21.840400284 +0100
  248. @@ -6,6 +6,11 @@
  249. normalized_testroot = normalize_path (test.root)
  250. +-- Escape regexp special characters to form a proper regexp that correctly
  251. +-- checks for the given path.
  252. +escaped_testroot = string.gsub(normalized_testroot, "([*+.()[\\^$|?])",
  253. + function (x) return "\\" .. x end)
  254. +
  255. -- check default operation
  256. -- MinGW does not process the shebang in mtnopt; must invoke sh directly
  257. @@ -13,7 +18,7 @@
  258. -- Don't pass the full /bin/sh path, it looks like that doesn't always
  259. -- work under mingw.
  260. check({"sh", "./mtnopt"}, 0, true)
  261. -check(qgrep('^MTN_database="' .. normalized_testroot .. '/test.db";$', "stdout"))
  262. +check(qgrep('^MTN_database="' .. escaped_testroot .. '/test.db";$', "stdout"))
  263. check(qgrep('^MTN_branch="testbranch";$', "stdout"))
  264. -- check operation with a specific key and just returning the value
  265. Index: monotone-1.0/test/src/testlib.lua
  266. ===================================================================
  267. --- test/src/testlib.lua 2012-04-28 15:41:51.595817578 +0100
  268. +++ test/src/testlib.lua 2012-04-28 15:43:21.841400246 +0100
  269. @@ -144,6 +144,22 @@
  270. return n
  271. end
  272. +-- encodes a query by percent escaping reserved characters (as defined
  273. +-- in RFC 3986) - except for the directory separator ('/').
  274. +function url_encode_path(path)
  275. + path = string.gsub(path, "([!*'();:@&=+$,?#[%]])",
  276. + function (x) return string.format("%%%02X", string.byte(x)) end)
  277. + return string.gsub(path, " ", "+")
  278. +end
  279. +
  280. +-- encodes a query by percent escaping reserved characters (as defined
  281. +-- in RFC 3986) - except for the ampersand and equal sign ('&', '=')
  282. +function url_encode_query(path)
  283. + path = string.gsub(path, "([!*'();:@+$,/?#[%]])",
  284. + function (x) return string.format("%%%02X", string.byte(x)) end)
  285. + return string.gsub(path, " ", "+")
  286. +end
  287. +
  288. function open_or_err(filename, mode, depth)
  289. local file, e = io.open(filename, mode)
  290. if file == nil then