curl / trurl

a command line tool for URL parsing and manipulation.
https://curl.se/trurl/
Other
3.19k stars 100 forks source link

trurl: allow "control bytes" in JSON output #333

Closed bagder closed 2 months ago

bagder commented 2 months ago

For example when doing

trurl 'http://example.org/%18' --json

Adapted and extended test cases to verify.

Fixes #262 Reported-by: Emanuele Torre

emanuele6 commented 2 months ago

@bagder This patch fixed --json, but not -g {path}:

$ ./trurl 'http://example.org/%18' -g '{path}'
trurl note: URL decode error, most likely because of rubbish in the input (path)
bagder commented 2 months ago

Correct, as I like to focus on one thing per issue but also that the "regular" output is different and might need other considerations. Should we really allow control codes to be output like this?

emanuele6 commented 2 months ago

Correct, as I like to focus on one thing per issue

I mentioned it because this PR closed #262

Should we really allow control codes to be output like this?

I don't see why not, also note that this is only causing errors for non-query: gets:

$ trurl -g '{fragment}' 'https://example.org/compiler#def%20main:%20%0a%09print%20"hello"'
trurl note: URL decode error, most likely because of rubbish in the input (fragment)

$ trurl -g '{query:code}' 'https://example.org/compiler?code=def%20main:%0a%09print%20"hello"'                                                
def main:
    print "hello"

Incidentally, unrelated, but I have noticed that -g {query:blah} doesn't convert +=>

$ trurl -g '{query:code}' 'https://example.org/compiler?code=def+main:%0a%09print+"hello"'
def+main:
    print+"hello"
bagder commented 2 months ago

Incidentally, unrelated, but I have noticed that -g {query:blah} doesn't convert +=>

It does now! :grin: