Fix RPC console parser to handle escaped arguments more like bash #1758

pull laanwj wants to merge 2 commits into bitcoin:master from laanwj:2012_08_uiconsole_parsing changing 1 files +111 −22
  1. laanwj commented at 7:47 PM on August 30, 2012: member

    As boost was no longer helpful I had to implement the command line splitting myself. Should fix issue #1750, but does need some testing.

  2. gmaxwell commented at 8:14 PM on August 30, 2012: contributor

    ACK. Works great for me. (tried a number of raw transactions on testnet with it)

  3. Diapolo commented at 9:19 PM on August 30, 2012: none

    I'll take a look at this tomorrow and see if the Windows weirdness is solved by this.

  4. Diapolo commented at 6:31 AM on August 31, 2012: none

    2 suggestions:

    1. I would like to see a general comment in the code, which explains what is covered by parseCommandLine().
    2. I tried the code with the example from the issue thread.

    Works: addmultisigaddress 2 '["02404c0b780b0d3f70a57bccb0cac31c77e980d899db00f04a61052cf6500bde23","02092eb733ce9027fcddb9917e841057c747318ff973de7a7768da9b3f039d6892"]'

    Fails: addmultisigaddress 2 '[\"02404c0b780b0d3f70a57bccb0cac31c77e980d899db00f04a61052cf6500bde23\",\"02092eb733ce9027fcddb9917e841057c747318ff973de7a7768da9b3f039d6892\"]'

    The problem I see here is the RPC error message, which says: Error: Error parsing JSON:[\"02404c0b780b0d3f70a57bccb0cac31c77e980d899db00f04a61052cf6500bde23\",\"02092eb733ce9027fcddb9917e841057c747318ff973de7a7768da9b3f039d6892\"]

    So when using an input exactly like shown in the error message the command should not fail or perhaps it would be better to update the RPC commands help and error messages.

    But I love the approach to don't need to escape on Windows :).

  5. laanwj commented at 6:59 AM on August 31, 2012: member

    That is as expected. You must not escape ' within " and ' within ". The reason for having two types of quotes in the first place is that you can avoid escaping.

    Shells have the same behavior. Try in bash echo "'". It will print literally '.

    If there is a help message that makes you do differently that's a separate issue. Which help message is wrong? Btw this still has nothing to do with windows. All the code involved is platform independent.

  6. Diapolo commented at 7:12 AM on August 31, 2012: none

    @laanwj I was not quite sure, if the code was platform independent, that is why I mentioned Windows.

    Just enter addmultisigaddress for example and take a look at the message. It clearly mentions <'[\"key\",\"key\"]'>, which makes users think they need to specify \" instead of just " (which works after your patch).

  7. gavinandresen commented at 12:54 PM on August 31, 2012: contributor

    ACK.

    Help should be fixed (and we need a new syntax for specifying optional arguments), but that's a separate issue.

  8. Fix RPC console parser to handle escaped arguments more like bash
    - Fix issue #1750
    576b5efe93
  9. In RPC console, attempt to format errors
    Try to display a nicer message instead of dumping raw JSON object when possible. If the error
    somehow doesn't have the required 'code' and 'message' fields, fall back to printing raw JSON object.
    b5c1467a7d
  10. laanwj commented at 3:45 PM on August 31, 2012: member

    Help (as in the help X command) was already working. It seems that what @diapolo was seeing is that error messages are dumped as raw JSON object, instead of formatted (and that you get help for free as error if you issue an command without the needed # of arguments).

    I've added basic formatting for errors. I've also added a doxygen comment to explain what parseCommand does.

  11. gmaxwell commented at 3:48 PM on August 31, 2012: contributor

    ACK.

    Perhaps we should do the error formating for bitcoind output too?

  12. laanwj commented at 5:48 AM on September 1, 2012: member

    Indeed, the error reporting there ( https://github.com/bitcoin/bitcoin/blob/master/src/bitcoinrpc.cpp#L1184 ) could be changed in the same way, to prevent similar confusion.

  13. gmaxwell referenced this in commit ddbddcb31e on Sep 1, 2012
  14. gmaxwell merged this on Sep 1, 2012
  15. gmaxwell closed this on Sep 1, 2012

  16. owlhooter referenced this in commit 3f3705c476 on Oct 10, 2018
  17. DrahtBot locked this on Sep 8, 2021

github-metadata-mirror

This is a metadata mirror of the GitHub repository bitcoin/bitcoin. This site is not affiliated with GitHub. Content is generated from a GitHub metadata backup.
generated: 2026-04-13 15:16 UTC

This site is hosted by @0xB10C
More mirrored repositories can be found on mirror.b10c.me