Page MenuHomeFreeBSD

git-arc: Do not echo unescaped literals to jq
ClosedPublic

Authored by jlduran on Sep 24 2024, 12:39 AM.
Tags
None
Referenced Files
Unknown Object (File)
Nov 24 2024, 11:41 AM
Unknown Object (File)
Nov 15 2024, 6:31 PM
Unknown Object (File)
Nov 15 2024, 6:22 PM
Unknown Object (File)
Nov 5 2024, 10:54 PM
Unknown Object (File)
Nov 2 2024, 10:02 PM
Unknown Object (File)
Oct 25 2024, 1:30 PM
Unknown Object (File)
Oct 23 2024, 7:10 PM
Unknown Object (File)
Oct 9 2024, 12:05 PM
Subscribers

Details

Summary

Store the json blobs in temporary files instead of variables, and feed
them to jq for parsing.

When echoing "\n", the new line will become a literal new line, and
therefore, invalid json input:

jq: parse error: Invalid string: control characters from U+0000 through U+001F must be escaped ...

To reproduce:

% git arc patch -c D12345

Diff Detail

Repository
rG FreeBSD src repository
Lint
Lint Skipped
Unit
Tests Skipped
Build Status
Buildable 59576
Build 56463: arc lint + arc unit

Event Timeline

I'm not a big fan of making temporary files, but I don't know how else to fix it.

I think this looks good

This revision is now accepted and ready to land.Sep 24 2024, 12:41 AM

Thank you.. Hmm I am pretty sure I included @emaste in the review. Well, still learning git-arc.

Looks ok to me, thank you.

I think I know how to achieve the same result using printf, and escaping literals with %s.
Regardless, I only have one more patch for git-arc (git arc list) that may benefit of review_data being in a file. If it turns out otherwise, I can "revert" to using variables.
I'm done trying out this great article on the topic.
Thank you for the reviews!

In D46767#1066872, @jlduran_gmail.com wrote:

I think I know how to achieve the same result using printf, and escaping literals with %s.
Regardless, I only have one more patch for git-arc (git arc list) that may benefit of review_data being in a file. If it turns out otherwise, I can "revert" to using variables.
I'm done trying out this great article on the topic.
Thank you for the reviews!

I think using files is fine. We don't care about the cost of creating a few extra temporary files here.

0mp added a subscriber: 0mp.
0mp added inline comments.
tools/tools/git/git-arc.sh
552

Note: backslashes are not necessary after a pipe. However, this style bit is already inconsistent in this file, so it's just a note and not a request for changes :)

This revision was automatically updated to reflect the committed changes.
des added inline comments.
tools/tools/git/git-arc.sh
584

whenever you create a temporary file, you should set a trap to delete it on exit, e.g.

trap 'rc=$?; rm -f "$review_data" "$user_data" "$diff_data" "$tmp"; trap - 0; exit $rc' 0 1 2 3 5 10 15

this is easier if you use a temporary directory instead, as you can just rm -rf the directory.

tools/tools/git/git-arc.sh
584

Great suggestion. Since it is already committed, I'll add the trap on a separate commit. Thank you!

jlduran added inline comments.
tools/tools/git/git-arc.sh
584

Done in D47289