feat: uri decode function (#3161)

This commit is contained in:
fletcher gornick authored and GitHub committed 2024-08-22 08:07:24 +09:00
1 parent 0b5ae30f19
commit 0e0cdd552e
7 files changed
+105 -5

No files matched your search

+6 -1
View File
@@ -61,7 +61,7 @@ null
null
"interpolation"
@text,@json,([1,.]|@csv,@tsv),@html,@uri,@sh,(@base64|.,@base64d)
@text,@json,([1,.]|@csv,@tsv),@html,(@uri|.,@urid),@sh,(@base64|.,@base64d)
"!()<>&'\"\t"
"!()<>&'\"\t"
"\"!()<>&'\\\"\\t\""
@@ -69,6 +69,7 @@ null
"1\t!()<>&'\"\\t"
"!()&lt;&gt;&amp;&apos;&quot;\t"
"%21%28%29%3C%3E%26%27%22%09"
"!()<>&'\"\t"
"'!()<>&'\\''\"\t'"
"ISgpPD4mJyIJ"
"!()<>&'\"\t"
@@ -86,6 +87,10 @@ null
"\u03bc"
"%CE%BC"
@urid
"%CE%BC"
"\u03bc"
@html "<b>\(.)</b>"
"<script>hax</script>"
"<b>&lt;script&gt;hax&lt;/script&gt;</b>"
+38
View File
@@ -0,0 +1,38 @@
# Tests are groups of three lines: program, input, expected output
# Blank lines and lines starting with # are ignored
@uri
"<>&'\"\t"
"%3C%3E%26%27%22%09"
# decoding encoded output results in same text
(@uri|@urid)
"<>&'\"\t"
"<>&'\"\t"
# testing variable length unicode characters
@uri
"a \u03bc \u2230 \ud83d\ude0e"
"a%20%CE%BC%20%E2%88%B0%20%F0%9F%98%8E"
@urid
"a%20%CE%BC%20%E2%88%B0%20%F0%9F%98%8E"
"a \u03bc \u2230 \ud83d\ude0e"
### invalid uri strings
# unicode character should be length 4 (not 3)
. | try @urid catch .
"%F0%93%81"
"string (\"%F0%93%81\") is not a valid uri encoding"
# invalid hex value ('FX')
. | try @urid catch .
"%FX%9F%98%8E"
"string (\"%FX%9F%98%8E\") is not a valid uri encoding"
# trailing utf-8 octets must be formatted like 10xxxxxx
# 'C0' = 11000000 invalid
. | try @urid catch .
"%F0%C0%81%8E"
"string (\"%F0%C0%81%8E\") is not a valid uri encoding"
Executable
+5
View File
@@ -0,0 +1,5 @@
#!/bin/sh
. "${0%/*}/setup" "$@"
$VALGRIND $Q $JQ -L "$mods" --run-tests $JQTESTDIR/uri.test