[build-path-prefix-map-spec] 15/50: Document the test cases that convinced me to drop the hex-encoding
Ximin Luo
infinity0 at debian.org
Fri Mar 10 15:17:19 UTC 2017
This is an automated email from the git hooks/post-receive script.
infinity0 pushed a commit to branch master
in repository build-path-prefix-map-spec.
commit 2948031046a6c7b1c1d17a876c483d59bc6b47ef
Author: Ximin Luo <infinity0 at debian.org>
Date: Fri Jan 27 17:48:24 2017 +0100
Document the test cases that convinced me to drop the hex-encoding
---
consume/hexsplit.js | 1 +
consume/hexsplit.py | 9 ++++++---
consume/testcases/hexsplit.0.no-unicode-decode.env | 1 +
consume/testcases/hexsplit.0.no-unicode-decode.in | 1 +
consume/testcases/hexsplit.0.no-unicode-decode.out | 1 +
consume/testcases/hexsplit.1.invalid-%00.env | 1 +
.../{hexsplit.0.allbytes-ok.in => hexsplit.1.invalid-%00.in} | 0
.../{hexsplit.1.invalid-hex.out => hexsplit.1.invalid-%00.out} | 0
8 files changed, 11 insertions(+), 3 deletions(-)
diff --git a/consume/hexsplit.js b/consume/hexsplit.js
index cda20da..8c58ed2 100755
--- a/consume/hexsplit.js
+++ b/consume/hexsplit.js
@@ -1,6 +1,7 @@
#!/usr/bin/nodejs
var unquote = function(x) {
+ if (x.indexOf("%00") >= 0) throw "invalid value: " + x;
var parts = x.split(/=/g).map(decodeURIComponent);
if (parts.length !== 2) throw "invalid value: " + x;
return parts;
diff --git a/consume/hexsplit.py b/consume/hexsplit.py
index f1742a0..7768214 100755
--- a/consume/hexsplit.py
+++ b/consume/hexsplit.py
@@ -5,10 +5,12 @@ import sys
# Parsing the variable
+chr_n0 = lambda x: (1/x, chr(x))[1]
+
def _dequote(part):
subs = part.split("%")
- # Will raise if there are <2 chars after % or if these aren't valid hex
- return subs[0] + "".join(chr(int(sub[0:2], 16)) + sub[2:] for sub in subs[1:])
+ # Will raise if there are <2 chars after % or if these aren't valid hex or if it is %00
+ return subs[0] + "".join(chr_n0(int(sub[0:2], 16)) + sub[2:] for sub in subs[1:])
def decode(prefix_str):
tuples = (part.split("=") for part in prefix_str.split(":") if part)
@@ -26,4 +28,5 @@ def map_prefix(string, pm):
return string
for v in sys.argv[1:]:
- print(map_prefix(v, pm))
+ # print() tries to auto-encode its args without surrogateescape
+ sys.stdout.buffer.write(map_prefix(v, pm).encode("utf-8", errors="surrogateescape") + b"\n")
diff --git a/consume/testcases/hexsplit.0.no-unicode-decode.env b/consume/testcases/hexsplit.0.no-unicode-decode.env
new file mode 100644
index 0000000..96c5ba5
--- /dev/null
+++ b/consume/testcases/hexsplit.0.no-unicode-decode.env
@@ -0,0 +1 @@
+/a/b%ff%ffyyy=ERROR:/a=lol:/b=foo:%ff=a
diff --git a/consume/testcases/hexsplit.0.no-unicode-decode.in b/consume/testcases/hexsplit.0.no-unicode-decode.in
new file mode 100644
index 0000000..29e181e
--- /dev/null
+++ b/consume/testcases/hexsplit.0.no-unicode-decode.in
@@ -0,0 +1 @@
+�
diff --git a/consume/testcases/hexsplit.0.no-unicode-decode.out b/consume/testcases/hexsplit.0.no-unicode-decode.out
new file mode 100644
index 0000000..7898192
--- /dev/null
+++ b/consume/testcases/hexsplit.0.no-unicode-decode.out
@@ -0,0 +1 @@
+a
diff --git a/consume/testcases/hexsplit.1.invalid-%00.env b/consume/testcases/hexsplit.1.invalid-%00.env
new file mode 100644
index 0000000..505273f
--- /dev/null
+++ b/consume/testcases/hexsplit.1.invalid-%00.env
@@ -0,0 +1 @@
+/a/b%00yyy=ERROR:/a=lol:/b=foo:/a/b%3dyyy=secreteh
diff --git a/consume/testcases/hexsplit.0.allbytes-ok.in b/consume/testcases/hexsplit.1.invalid-%00.in
similarity index 100%
copy from consume/testcases/hexsplit.0.allbytes-ok.in
copy to consume/testcases/hexsplit.1.invalid-%00.in
diff --git a/consume/testcases/hexsplit.1.invalid-hex.out b/consume/testcases/hexsplit.1.invalid-%00.out
similarity index 100%
copy from consume/testcases/hexsplit.1.invalid-hex.out
copy to consume/testcases/hexsplit.1.invalid-%00.out
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/reproducible/build-path-prefix-map-spec.git
More information about the Reproducible-commits
mailing list