Skip to content

fix(admin-control-panel): use depth-aware awk for robust Adminer block removal - #219

Merged
PDowney merged 4 commits into
masterfrom
copilot/fix-admin-tool-parse-issue
May 1, 2026
Merged

PDowney merged 4 commits into
masterfrom
copilot/fix-admin-tool-parse-issue

Conversation

Copilot AI commented Apr 30, 2026

Copy link
Copy Markdown
Contributor
  • Define CONTROL_PANEL_INDEX constant at the top of the Adminer removal block
  • Replace all 4 literal occurrences of /var/www/admin/control-panel/index.html with "${CONTROL_PANEL_INDEX}"
  • Update CHANGELOG.md
Original prompt
Please apply the following diffs and create a pull request.
Once the PR is ready, give it a title based on the messages of the fixes being applied.

[{"message":"The sed range pattern `/<div[^>]*id=\"adminer-tool\"[^>]*>/,/<\\/div>/p` will match the first `</div>` tag encountered after the opening div, which may not be the correct closing tag if there are nested divs. While lines 61-63 perform a sanity check, the extraction itself could capture an incorrect block. Consider using a more robust HTML parsing tool like `xmllint` or `pup` for reliable extraction, or ensure the sanity check is performed before relying on this block for validation logic.","fixFiles":[{"filePath":"scripts/install/tools/frontend/admin-control-panel-install.sh","diff":"diff --git a/scripts/install/tools/frontend/admin-control-panel-install.sh b/scripts/install/tools/frontend/admin-control-panel-install.sh\n--- a/scripts/install/tools/frontend/admin-control-panel-install.sh\n+++ b/scripts/install/tools/frontend/admin-control-panel-install.sh\n@@ -53,17 +53,52 @@\n     # To avoid corrupting the page if the structure has changed, first ensure that the expected\n     # single-line opening <div> for the Adminer card is present before applying the sed range.\n     if grep -q '<div[^>]*id=\"adminer-tool\"[^>]*>' \"/var/www/admin/control-panel/index.html\"; then\n-        # Extract the block that would be deleted, then perform a simple sanity check\n-        # to ensure there are no nested <div> elements that would cause a partial removal.\n+        # Extract the exact Adminer block using depth-aware matching so nested <div> elements\n+        # are handled correctly and we only stop at the true matching closing </div>.\n         adminer_block=\"$(\n-            sed -n '/<div[^>]*id=\"adminer-tool\"[^>]*>/,/<\\/div>/p' \"/var/www/admin/control-panel/index.html\"\n+            awk '\n+                BEGIN { in_block=0; depth=0 }\n+                {\n+                    line=$0\n+                    if (!in_block && line ~ /<div[^>]*id=\"adminer-tool\"[^>]*>/) {\n+                        in_block=1\n+                    }\n+                    if (in_block) {\n+                        print line\n+                        opens=gsub(/<div[^>]*>/, \"&\", line)\n+                        closes=gsub(/<\\/div>/, \"&\", line)\n+                        depth += opens - closes\n+                        if (depth == 0) {\n+                            exit\n+                        }\n+                    }\n+                }\n+            ' \"/var/www/admin/control-panel/index.html\"\n         )\"\n         open_div_count=$(printf '%s\\n' \"$adminer_block\" | grep -o '<div' | wc -l | tr -d '[:space:]')\n         close_div_count=$(printf '%s\\n' \"$adminer_block\" | grep -o '</div>' | wc -l | tr -d '[:space:]')\n-        if [[ \"$open_div_count\" -eq 1 && \"$close_div_count\" -eq 1 ]]; then\n-            sed -i '/<div[^>]*id=\"adminer-tool\"[^>]*>/,/<\\/div>/d' \"/var/www/admin/control-panel/index.html\"\n+        if [[ -n \"$adminer_block\" && \"$open_div_count\" -eq \"$close_div_count\" ]]; then\n+            awk '\n+                BEGIN { in_block=0; depth=0 }\n+                {\n+                    line=$0\n+                    if (!in_block && line ~ /<div[^>]*id=\"adminer-tool\"[^>]*>/) {\n+                        in_block=1\n+                    }\n+                    if (in_block) {\n+                        opens=gsub(/<div[^>]*>/, \"&\", line)\n+                        closes=gsub(/<\\/div>/, \"&\", line)\n+                        depth += opens - closes\n+                        if (depth == 0) {\n+                            in_block=0\n+                        }\n+                        next\n+                    }\n+                    print line\n+                }\n+            ' \"/var/www/admin/control-panel/index.html\" > \"/var/www/admin/control-panel/index.html.tmp\" && mv \"/var/www/admin/control-panel/index.html.tmp\" \"/var/www/admin/control-panel/index.html\"\n         else\n-            echo \"Warning: Adminer tool block appears to contain nested <div> elements; skipping Adminer card removal to avoid corrupting index.html.\" >&2\n+            echo \"Warning: Adminer tool block appears malformed or unmatched; skipping Adminer card removal to avoid corrupting index.html.\" >&2\n         fi\n     else\n         echo \"Warning: Expected <div> with id=\\\"adminer-tool\\\" not found in index.html; skipping Adminer card removal.\" >&2\n"}]},{"message":"The pattern `<div` will match any occurrence of the string '<div' including cases like `<div-custom-element>` or text containing '<div'. Use `'<div[> ]'` or a more precise pattern to match only actual `<div>` opening tags. Similarly, ensure `</div>` matching is accurate and not matching strings within comments or text content.","fixFiles":[{"filePath":"scripts/install/tools/frontend/admin-control-panel-install.sh","diff":"diff --git a/scripts/install/tools/fronte...

…al and improve div grep patterns

Agent-Logs-Url: https://github.com/EngineScript/EngineScript/sessions/d696b39d-35bd-4593-8c93-5ec244db494d

Co-authored-by: PDowney <11467177+PDowney@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix HTML extraction issue in admin control panel install script fix(admin-control-panel): use depth-aware awk for robust Adminer block removal Apr 30, 2026
Copilot AI requested a review from PDowney April 30, 2026 08:14
Copilot finished work on behalf of PDowney May 1, 2026 00:34
Removed outdated entries for the admin control panel installation and robust Adminer block removal from the changelog.
@github-actions

github-actions Bot commented May 1, 2026

Copy link
Copy Markdown

Dependency Review

✅ No vulnerabilities or license issues or OpenSSF Scorecard issues found.

Scanned Files

None

@sonarqubecloud

sonarqubecloud Bot commented May 1, 2026

Copy link
Copy Markdown

@PDowney
PDowney marked this pull request as ready for review May 1, 2026 00:51
Copilot AI review requested due to automatic review settings May 1, 2026 00:51
@PDowney
PDowney merged commit 0cf484e into master May 1, 2026
11 checks passed
@github-actions
github-actions Bot deleted the copilot/fix-admin-tool-parse-issue branch May 1, 2026 00:51

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Updates the Admin Control Panel install script to remove the Adminer card more robustly by replacing a fragile sed range delete with depth-aware awk parsing, and introduces a constant for the control panel index path.

Changes:

  • Define CONTROL_PANEL_INDEX and reuse it instead of repeating the full /var/www/admin/control-panel/index.html path.
  • Replace Adminer card extraction/removal logic with depth-aware awk to better handle nested <div> structures.
  • Tighten <div>/</div> counting in the sanity check used to validate the extracted block.

Comment on lines 46 to +48
# Remove Adminer tool card if INSTALL_ADMINER=0
if [[ "${INSTALL_ADMINER}" -eq 0 ]]; then
CONTROL_PANEL_INDEX="/var/www/admin/control-panel/index.html"
Comment on lines 49 to 53
# NOTE: This sed range depends on the HTML structure of index.html:
# - the Adminer card must be wrapped in a single <div ... id="adminer-tool" ...> ... </div> block
# - the opening <div> with id="adminer-tool" and its matching closing </div> must each be on a single line
# - the block must not contain nested <div> elements whose closing tags appear before the end of the card
# If this structure changes, update this command (or switch to an HTML-aware tool) to avoid partial removal.
Comment on lines +64 to +71
if (!in_block && line ~ /<div[^>]*id="adminer-tool"[^>]*>/) {
in_block=1
}
if (in_block) {
print line
opens=gsub(/<div[^>]*>/, "&", line)
closes=gsub(/<\/div>/, "&", line)
depth += opens - closes
Comment on lines +86 to +92
if (!in_block && line ~ /<div[^>]*id="adminer-tool"[^>]*>/) {
in_block=1
}
if (in_block) {
opens=gsub(/<div[^>]*>/, "&", line)
closes=gsub(/<\/div>/, "&", line)
depth += opens - closes
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.

3 participants