Skip to content

🐛 Fix JS error on audit errors page when an extension adds a ready script - #1097

Open
Pierre-Ve wants to merge 1 commit into
Combodo:developfrom
Pierre-Ve:bugfix/audit-missing-semicolon
Open

Pierre-Ve wants to merge 1 commit into
Combodo:developfrom
Pierre-Ve:bugfix/audit-missing-semicolon

Conversation

@Pierre-Ve

Copy link
Copy Markdown

Base information

Question Answer
Related to a SourceForge thread / Another PR / A GitHub Issue / Combodo ticket? #1060
Type of change? Bug fix

Symptom (bug) / Objective (enhancement)

On the audit errors page (pages/audit.php?operation=errors&...), when an extension adds a ready script whose code starts with (, [ or a backtick, the browser console shows:

Uncaught TypeError: $(...).attr(...) is not a function

None of the ready scripts that come after this one run, including the extension's script.

Reproduction procedure (bug)

  1. On iTop 3.2.3

  2. With PHP 8.4.20

  3. Install an extension that injects a ready script starting with (, for example:

    class DemoReadyScript implements iBackofficeReadyScriptExtension
    {
        public function GetReadyScript(): string
        {
            return "(function () { console.log('demo'); })();";
        }
    }
  4. Go to Admin tools > Audit, run an audit, and click the error count of any rule that has errors

  5. Open the browser console

  6. Expected: the page works, and the extension's script and the other ready scripts run. Actual: Uncaught TypeError: $(...).attr(...) is not a function, and the following ready scripts don't run.

Cause (bug)

In pages/audit.php, case 'errors', the ready script that rewrites the export link has no trailing semicolon:

$oP->add_ready_script("$('a[href*=\"pages/UI.php?operation=search\"]').attr('href', '".$sExportUrl."')");

templates/pages/backoffice/webpage/layout.html.twig outputs the ready scripts one after another, separated only by newlines, and extension ready scripts are added after this one. If the next script starts with (, [ or a backtick, JavaScript does not insert a semicolon automatically, so the browser reads:

$('a[href*="pages/UI.php?operation=search"]').attr('href', '...')
(function () { console.log('demo'); })();

and tries to call the jQuery object returned by .attr() as a function.

Proposed solution (bug and enhancement)

Add the missing ; at the end of that script, as the other add_ready_script() calls in the same file already do.

Checklist before requesting a review

  • If my PR is a bug fix or an enhancement, I opened an issue that got reviewed and approved by Combodo
  • I have performed a self-review of my code
  • I have tested all changes I made on an iTop instance
  • I have added a unit test, otherwise I have explained why I couldn't
  • Is the PR clear and detailed enough so anyone can understand without digging in the code?

No unit test added: the fix is a one-character change inside a generated JavaScript string, and the bug only shows up in the browser when the page's ready scripts are concatenated, which the PHPUnit suite doesn't cover

Copilot AI balanced review requested due to automatic review settings October 26, 2026 22:03

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.

🟢 Approval recommended

No active review issues are reported for the audit errors page’s script-termination fix.

No open issues 🎉

What changed in this PR

Fixes the audit errors page’s JavaScript concatenation issue described in #1060, allowing extension ready scripts and subsequent scripts to run correctly.

Changes:

  • Adds a trailing semicolon to the ready script that rewrites the export link, preventing it from merging with the next script.
File Description
pages/​audit.php Terminates the export-link ready script with a semicolon.

Review effort: Balanced

@github-project-automation github-project-automation Bot moved this to Pending review in Combodo PRs dashboard Oct 27, 2026
@Molkobain Molkobain added the bug Something isn't working label Oct 28, 2026
@Molkobain

Copy link
Copy Markdown
Member

Thanks for the PR!

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

Status: Pending review

Development

Successfully merging this pull request may close these issues.

4 participants