Skip to content

Commit 3a3a4fd

Browse files
authored
[plan] do not html-escape json encoding (#170)
## Summary In our `plan.json` that we generate the ampersand gets escaped. This happens because golang does html escaping by default in its json/encoding. Hard for it to escape its web roots, I guess. Anyway, there's no reason ampersands cannot exist in jsons, so we can turn off this escaping. ## How was it tested? tests pass, so current testdata plan.json all work. made this edit to a zig testdatum: ```➜ git diff diff --git a/testdata/zig/zig-hello-world/devbox.json b/testdata/zig/zig-hello-world/devbox.json index 3352a1b..498559e 100644 --- a/testdata/zig/zig-hello-world/devbox.json +++ b/testdata/zig/zig-hello-world/devbox.json @@ -2,5 +2,8 @@ "packages": [], "shell": { "init_hook": null - } -} \ No newline at end of file + }, + "start_stage": { + "command": "./zig-hello-world && echo \"used ampersand\"" + } +} ``` and got this output ``` { "dev_packages": [ "zig" ], "runtime_packages": [], "install_stage": { "command": "" }, "build_stage": { "command": "zig build install", "input_files": [ "." ] }, "start_stage": { "command": "./zig-hello-world && echo \"used ampersand\"", "input_files": [ "./zig-out/bin/" ] }, "definitions": null } ```
1 parent f7518a5 commit 3a3a4fd

File tree

4 files changed

+38
-31
lines changed

4 files changed

+38
-31
lines changed

boxcli/plan.go

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@
44
package boxcli
55

66
import (
7-
"fmt"
7+
"encoding/json"
8+
"os"
89

910
"github.com/pkg/errors"
1011
"github.com/spf13/cobra"
@@ -37,6 +38,9 @@ func runPlanCmd(cmd *cobra.Command, args []string) error {
3738
if plan.Invalid() {
3839
return plan.Error()
3940
}
40-
fmt.Println(plan)
41-
return nil
41+
42+
enc := json.NewEncoder(os.Stdout)
43+
enc.SetIndent("", " ")
44+
enc.SetEscapeHTML(false)
45+
return errors.WithStack(enc.Encode(plan))
4246
}
Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,13 @@
11
{
2+
"dev_packages": [
3+
"python310",
4+
"poetry"
5+
],
6+
"runtime_packages": [
7+
"python310"
8+
],
29
"install_stage": {
3-
"command": "poetry add pex -n --no-ansi \u0026\u0026 poetry install --no-dev -n --no-ansi",
10+
"command": "poetry add pex -n --no-ansi && poetry install --no-dev -n --no-ansi",
411
"input_files": [
512
"."
613
]
@@ -14,11 +21,5 @@
1421
"."
1522
]
1623
},
17-
"dev_packages": [
18-
"python310",
19-
"poetry"
20-
],
21-
"runtime_packages": [
22-
"python310"
23-
]
24-
}
24+
"definitions": null
25+
}
Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,13 @@
11
{
2+
"dev_packages": [
3+
"python310",
4+
"poetry"
5+
],
6+
"runtime_packages": [
7+
"python310"
8+
],
29
"install_stage": {
3-
"command": "poetry add pex -n --no-ansi \u0026\u0026 poetry install --no-dev -n --no-ansi",
10+
"command": "poetry add pex -n --no-ansi && poetry install --no-dev -n --no-ansi",
411
"input_files": [
512
"."
613
]
@@ -14,11 +21,5 @@
1421
"."
1522
]
1623
},
17-
"dev_packages": [
18-
"python310",
19-
"poetry"
20-
],
21-
"runtime_packages": [
22-
"python310"
23-
]
24-
}
24+
"definitions": null
25+
}
Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,25 @@
11
{
2+
"dev_packages": [
3+
"python310",
4+
"poetry"
5+
],
6+
"runtime_packages": [
7+
"python310"
8+
],
29
"install_stage": {
3-
"command": "poetry add pex -n --no-ansi \u0026\u0026 poetry install --no-dev -n --no-ansi",
10+
"command": "poetry add pex -n --no-ansi && poetry install --no-dev -n --no-ansi",
411
"input_files": [
512
"."
613
]
714
},
815
"build_stage": {
9-
"command": "poetry run pex . -o app.pex $(poetry run python -c \"import pkgutil;import poetry_with_scripts;modules = [name for _, name, _ in pkgutil.iter_modules(poetry_with_scripts.__path__)];print('-m poetry_with_scripts' if '__main__' in modules else '--script script');\") --validate-entry-point \u0026\u003e/dev/null || (echo 'Build failed. Could not find entrypoint' \u0026\u0026 exit 1)"
16+
"command": "poetry run pex . -o app.pex $(poetry run python -c \"import pkgutil;import poetry_with_scripts;modules = [name for _, name, _ in pkgutil.iter_modules(poetry_with_scripts.__path__)];print('-m poetry_with_scripts' if '__main__' in modules else '--script script');\") --validate-entry-point &>/dev/null || (echo 'Build failed. Could not find entrypoint' && exit 1)"
1017
},
1118
"start_stage": {
1219
"command": "python ./app.pex",
1320
"input_files": [
1421
"."
1522
]
1623
},
17-
"dev_packages": [
18-
"python310",
19-
"poetry"
20-
],
21-
"runtime_packages": [
22-
"python310"
23-
]
24-
}
24+
"definitions": null
25+
}

0 commit comments

Comments
 (0)