Repository navigation
common: unescape the string form of param_string_or_array - #9598
Open
Mohil-Ahuja wants to merge 1 commit into
Open
Mohil-Ahuja wants to merge 1 commit into
Mohil-Ahuja wants to merge 1 commit into
Conversation
dev-splice documents that script segments are "separated by newlines or
semicolons", and the script tokenizer treats '\n' as a delimiter, yet a
newline-separated script sent over JSON-RPC fails to compile:
"message":"Splice script compile failed",
"compiler_error":["Missing sat amount. A sat amount or '*' is
required here", ..., "Compiler phase: validate_and_clean"]
while the same script with ';' separators works.
The script never contains a newline. dev-splice reads script_or_json
through param_string_or_array(), whose string case calls param_string(),
which copies the raw token bytes. A JSON "\n" escape therefore reaches
parse_splice_script() as a backslash followed by 'n', which is neither a
delimiter nor whitespace, so the segments are never split. lightning-cli
JSON-encodes its arguments, so the same happens there.
Use param_escaped_string() for the string case so escapes are decoded,
as they already are for free-text parameters such as invoice
descriptions. dev-splice is the only caller of param_string_or_array().
Fixes: ElementsProject#9553
Changelog-Fixed: JSON-RPC: `dev-splice` accepts scripts whose segments are separated by newlines, as documented.
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #9553.
dev-splicescripts with segments separated by real newlines fail to compile over JSON-RPC, althoughdoc/dev-splice.7.mdsays segments are "separated by newlines or semicolons" and the tokenizer incommon/splice_script.calready treats'\n'asTOK_DELIMITER. The same script with;works.The tokenizer is fine; the script just never contains a newline.
dev-splicereadsscript_or_jsonthroughparam_string_or_array(), whose string case falls through toparam_string(), which copies the raw token bytes without decoding escapes. A JSON"\n"escape therefore arrives inparse_splice_script()as a backslash followed byn. You can see it in the report: the compiler error echoes the script back with a literal backslash-n where the segment break should be.lightning-cliJSON-encodes its arguments, which is why the$'...\n...'form fails the same way.The fix is one line: use
param_escaped_string()for the string case, the same helper used for other free-text parameters such as invoice descriptions.dev-spliceis the only caller ofparam_string_or_array(), so nothing else changes behaviour. The array case is untouched.Tests
Added
string_or_array()tocommon/test/run-param.c, covering a"\n"escape decoding to a newline, an escaped backslash, and the array path being passed through.Assertion `streq(res->str, "wallet -> 1sat\n1sat -> x")' failedI also ran the other unit tests that compile in
json_param.c(run-bolt11,run-json_filter,run-json_remove) andrun-splice_script; all pass. I haven't run the Python integration suite.One behaviour note:
param_escaped_string()rejects\uescapes, so a script containing one now gets a clear "should be a string (without \u)" error instead of reaching the compiler. Scripts are plain ASCII keywords, amounts and ids, so I don't think that matters, but I'm mentioning it in case you'd rather handle it differently.Checklist
tools/lightning-downgrade. (No persistent state is touched.)