-
Notifications
You must be signed in to change notification settings - Fork 156
fix(code-server,vscode-web): parse JSONC in extensions.json with sed #798
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -116,6 +116,17 @@ for extension in "$${EXTENSIONLIST[@]}"; do | |||||||||||||||||||||||||||||||||||||||||||
| fi | ||||||||||||||||||||||||||||||||||||||||||||
| done | ||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||
| # Strip JSONC features (block/line comments, trailing commas) for jq parsing | ||||||||||||||||||||||||||||||||||||||||||||
| strip_jsonc_for_extensions() { | ||||||||||||||||||||||||||||||||||||||||||||
| sed 's|//.*||g' "$1" | sed -E ' | ||||||||||||||||||||||||||||||||||||||||||||
| :a | ||||||||||||||||||||||||||||||||||||||||||||
| N | ||||||||||||||||||||||||||||||||||||||||||||
| $!ba | ||||||||||||||||||||||||||||||||||||||||||||
| s#/[*]([^*]|[*]+[^*/])*[*]+/##g | ||||||||||||||||||||||||||||||||||||||||||||
| s/,[^]}"]*([]}])/\1/g | ||||||||||||||||||||||||||||||||||||||||||||
| ' | ||||||||||||||||||||||||||||||||||||||||||||
|
DevelopmentCats marked this conversation as resolved.
|
||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+119
to
+128
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. P1 —
The suggestion merges into a single
Suggested change
|
||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||
| if [ "${AUTO_INSTALL_EXTENSIONS}" = true ]; then | ||||||||||||||||||||||||||||||||||||||||||||
| if ! command -v jq > /dev/null; then | ||||||||||||||||||||||||||||||||||||||||||||
| echo "jq is required to install extensions from a workspace file." | ||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -143,8 +154,8 @@ if [ "${AUTO_INSTALL_EXTENSIONS}" = true ]; then | |||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||
| if [ -n "$RECOMMENDATIONS_FILE" ]; then | ||||||||||||||||||||||||||||||||||||||||||||
| printf "🧩 Installing extensions from %s...\n" "$RECOMMENDATIONS_FILE" | ||||||||||||||||||||||||||||||||||||||||||||
| # Use sed to remove single-line comments before parsing with jq | ||||||||||||||||||||||||||||||||||||||||||||
| extensions=$(sed 's|//.*||g' "$RECOMMENDATIONS_FILE" | jq -r "$RECOMMENDATIONS_QUERY") | ||||||||||||||||||||||||||||||||||||||||||||
| # Strip JSONC comments and trailing commas before parsing with jq | ||||||||||||||||||||||||||||||||||||||||||||
| extensions=$(strip_jsonc_for_extensions "$RECOMMENDATIONS_FILE" | jq -r "$RECOMMENDATIONS_QUERY") | ||||||||||||||||||||||||||||||||||||||||||||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. P1 — This PR upgrades # vscode-web/run.sh (this PR)
RECOMMENDATIONS_QUERY='(.recommendations // [])[]'but RECOMMENDATIONS_QUERY=".recommendations[]"A valid Fix (line 137, not in the diff hunk above — apply manually): - RECOMMENDATIONS_QUERY=".recommendations[]"
+ RECOMMENDATIONS_QUERY='(.recommendations // [])[]'Note the single-quote change: the expression contains no shell variables, so single quotes are correct and prevent accidental expansion.
|
||||||||||||||||||||||||||||||||||||||||||||
| for extension in $extensions; do | ||||||||||||||||||||||||||||||||||||||||||||
| if extension_installed "$extension"; then | ||||||||||||||||||||||||||||||||||||||||||||
| continue | ||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -150,15 +150,26 @@ for extension in "$${EXTENSIONLIST[@]}"; do | |||||||||||||||||||||||||||||||||||||||||
| fi | ||||||||||||||||||||||||||||||||||||||||||
| done | ||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
| # Strip JSONC features (block/line comments, trailing commas) for jq parsing | ||||||||||||||||||||||||||||||||||||||||||
| strip_jsonc_for_extensions() { | ||||||||||||||||||||||||||||||||||||||||||
| sed 's|//.*||g' "$1" | sed -E ' | ||||||||||||||||||||||||||||||||||||||||||
| :a | ||||||||||||||||||||||||||||||||||||||||||
| N | ||||||||||||||||||||||||||||||||||||||||||
| $!ba | ||||||||||||||||||||||||||||||||||||||||||
| s#/[*]([^*]|[*]+[^*/])*[*]+/##g | ||||||||||||||||||||||||||||||||||||||||||
| s/,[^]}"]*([]}])/\1/g | ||||||||||||||||||||||||||||||||||||||||||
|
DevelopmentCats marked this conversation as resolved.
|
||||||||||||||||||||||||||||||||||||||||||
| ' | ||||||||||||||||||||||||||||||||||||||||||
|
DevelopmentCats marked this conversation as resolved.
|
||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+153
to
+162
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. P1 — URL corruption / single-line file: stage ordering is wrong The current implementation pipes through a line-comment stripper before slurping into a multi-line buffer: sed 's|//.*||g' "$1" | sed -E '
:a
N
$!ba
s#/[*]([^*]|[*]+[^*/])*[*]+/##g
...Two verified failure modes:
Fix: slurp the whole file first, then strip block comments, then line comments — in a single
Suggested change
|
||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
| if [ "${AUTO_INSTALL_EXTENSIONS}" = true ]; then | ||||||||||||||||||||||||||||||||||||||||||
| if ! command -v jq > /dev/null; then | ||||||||||||||||||||||||||||||||||||||||||
| echo "jq is required to install extensions from a workspace file." | ||||||||||||||||||||||||||||||||||||||||||
| else | ||||||||||||||||||||||||||||||||||||||||||
| # Prefer WORKSPACE if set and points to a file | ||||||||||||||||||||||||||||||||||||||||||
| if [ -n "${WORKSPACE}" ] && [ -f "${WORKSPACE}" ]; then | ||||||||||||||||||||||||||||||||||||||||||
| printf "🧩 Installing extensions from %s...\n" "${WORKSPACE}" | ||||||||||||||||||||||||||||||||||||||||||
| # Strip single-line comments then parse .extensions.recommendations[] | ||||||||||||||||||||||||||||||||||||||||||
| extensions=$(sed 's|//.*||g' "${WORKSPACE}" | jq -r '(.extensions.recommendations // [])[]') | ||||||||||||||||||||||||||||||||||||||||||
| extensions=$(strip_jsonc_for_extensions "${WORKSPACE}" \ | ||||||||||||||||||||||||||||||||||||||||||
| | jq -r '(.extensions.recommendations // [])[]') | ||||||||||||||||||||||||||||||||||||||||||
| for extension in $extensions; do | ||||||||||||||||||||||||||||||||||||||||||
| $VSCODE_WEB "$EXTENSION_ARG" --install-extension "$extension" --force | ||||||||||||||||||||||||||||||||||||||||||
| done | ||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -170,7 +181,8 @@ if [ "${AUTO_INSTALL_EXTENSIONS}" = true ]; then | |||||||||||||||||||||||||||||||||||||||||
| fi | ||||||||||||||||||||||||||||||||||||||||||
| if [ -f "$WORKSPACE_DIR/.vscode/extensions.json" ]; then | ||||||||||||||||||||||||||||||||||||||||||
| printf "🧩 Installing extensions from %s/.vscode/extensions.json...\n" "$WORKSPACE_DIR" | ||||||||||||||||||||||||||||||||||||||||||
| extensions=$(sed 's|//.*||g' "$WORKSPACE_DIR/.vscode/extensions.json" | jq -r '.recommendations[]') | ||||||||||||||||||||||||||||||||||||||||||
| extensions=$(strip_jsonc_for_extensions "$WORKSPACE_DIR/.vscode/extensions.json" \ | ||||||||||||||||||||||||||||||||||||||||||
| | jq -r '(.recommendations // [])[]') | ||||||||||||||||||||||||||||||||||||||||||
| for extension in $extensions; do | ||||||||||||||||||||||||||||||||||||||||||
| $VSCODE_WEB "$EXTENSION_ARG" --install-extension "$extension" --force | ||||||||||||||||||||||||||||||||||||||||||
| done | ||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
Uh oh!
There was an error while loading. Please reload this page.