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
Added possibility to remove solidus symbol escaping #30
Conversation
Hi, it looks like you've introduced a bashism here, which means potential incompatibility with other shells. (a test or two might also be nice) |
As far as I can see, JSON.sh specifically asks for bash (#!/usr/bin/env bash), so that should not be a problem. Please let me know if this is not a case, I will try to come up with a workaround (though I would prefer not to add a dependency on awk or something like that). I've added the test cases. Thank you. |
Ah I didn't know about this. I initially generated the test cases with node's JSON.stringify, @aidanhs would this work in sh? I tried testing this but arch only wants to give me bash when i try install sh. |
We already rely on gawk if egrep misbehaves - Line 53 in 1df36d6
You could just use sed, or a while loop with expr if you wanted to stick to coreutils. Hadn't seen the shebang...I note a couple of bashisms have come back since my last effort so I guess this could be merged and I'll address it all separately. Regarding shell compatibility, dash:
fish:
|
(ignore my deleted comment, I got confused) |
Ok, maybe I should put the comment back.
I think what's going on in that final example is that solidus escaping is happening, so one of the backslashes is removed. But it shouldn't be, because the backslash is escaped? |
The thing is, a JSON generator that escapes solidus would not produce a string like: Example: <?php
$a = '\\/';
echo "Original string: " . $a . "\n";
echo "JSON: " . json_encode($a) . "\n";
?> Output: > php solidus.php
Original string: \/
JSON: "\\\/"
> cat ~/3.json
"\\\/"
> cat ~/3.json | ./JSON.sh -s
[] "\\/" |
Fair point. No more objections. I'll look at bashisms (and gawk) separately. |
Just a friendly reminder. |
merged into 0.2.0 |
According to http://json.org/, solidus symbol (forward slash) should be escaped as "/". Some JSON generators abide the rule and generate strings like "http://example.com/test".
I've added an option (-s) that provides possibility to normalize such strings and replace "/" with plain "/".