Skip to content

perl-for-cntrl-chars #34

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Jul 13, 2021
Merged

perl-for-cntrl-chars #34

merged 4 commits into from
Jul 13, 2021

Conversation

joesuf4
Copy link
Contributor

@joesuf4 joesuf4 commented Jul 12, 2021

No description provided.

Copy link
Owner

@kvaps kvaps left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi, @joesuf4 sorry for late answer. I'm going to review your PR

@@ -75,7 +75,7 @@ done
if [ $# -gt 0 ]; then
while [ $# -gt 0 ]; do
cmd="$cmd, \"$(echo "$1" | \
awk '{gsub(/\\/,"\\\\");gsub(/"/,"\\\"");gsub(/$/,"\\n");printf last}{last=$0} END{gsub(/\\n/,"",last);printf last}' \
perl -pl -0777 -e 's/([\\"])/\\$1/g;s/\n$//;s/\n/\\n/g;s/([\x01-\x1f])/sprintf "\\u%04x",ord $1/ge' \
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unfortunately perl is not installed on many systems by default, let's try using as less dependencies as we can.
Awk was a nice solution, and persist almost everywhere, so why not using it?

Copy link
Contributor Author

@joesuf4 joesuf4 Jul 12, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because it doesn't handle control-characters like 0x1b, which I need? https://datatracker.ietf.org/doc/html/rfc7159#section-7

Copy link
Contributor Author

@joesuf4 joesuf4 Jul 12, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Exactly which systems have kubectl installed, but not perl? Windows?

Copy link
Owner

@kvaps kvaps Jul 13, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Many of them, even linux distros: for example centos, alpine linux, archlinux have no it out of box.

@joesuf4 joesuf4 force-pushed the perl branch 3 times, most recently from 4a51f3a to 3ae2b92 Compare July 12, 2021 23:21
@joesuf4
Copy link
Contributor Author

joesuf4 commented Jul 12, 2021

If you want to implement most of the JSON spec faithfully, as it relates to the bulk of 7-bit ascii, you need to use something with more power than awk.

If you just want to support my use case, and stick to awk, that's also fine with me. This MR has that developed in the final commit.

@kvaps
Copy link
Owner

kvaps commented Jul 13, 2021

This become to be a madness.

I committed test.sh to check if we didn't brake anything and your suggesting of using [ -t 0 ] instead of ! [ -p /dev/stdin ] && ! [ -p /dev/stdout ]

please rebase your PR and run test.sh, because it is falling all three of them

@joesuf4
Copy link
Contributor Author

joesuf4 commented Jul 13, 2021

All tests pass. Should be good to go now. Thanks for the test suite!

@kvaps
Copy link
Owner

kvaps commented Jul 13, 2021

@joesuf4 thanks! Could you also add the test case you solving by this change?

@joesuf4
Copy link
Contributor Author

joesuf4 commented Jul 13, 2021

Done.

@kvaps kvaps merged commit a8b820a into kvaps:master Jul 13, 2021
@kvaps
Copy link
Owner

kvaps commented Jul 13, 2021

Perfect, thank you for contribution!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants