diff --git a/.github/workflows/plugin-ci-workflow.yml b/.github/workflows/plugin-ci-workflow.yml index 7580ee1..76612ac 100644 --- a/.github/workflows/plugin-ci-workflow.yml +++ b/.github/workflows/plugin-ci-workflow.yml @@ -187,6 +187,16 @@ jobs: echo "Syntax errors found!" exit 1 fi + + - name: Run Plugin Regression Tests + run: | + cd ${{ github.workspace }}/cacti/plugins/syslog + if [ -d tests/regression ]; then + for test in tests/regression/*.php; do + [ -f "$test" ] || continue + php "$test" + done + fi - name: Run Cacti Poller diff --git a/CHANGELOG.md b/CHANGELOG.md index 0f1e7f2..fb93014 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,7 @@ --- develop --- +* issue#260: Replace eval-based callback execution in autocomplete handling * issue: Making changes to support Cacti 1.3 * issue: Don't use MyISAM for non-analytical tables * issue: The install advisor for Syslog was broken in current Cacti releases diff --git a/js/functions.js b/js/functions.js index a96d47d..f242349 100644 --- a/js/functions.js +++ b/js/functions.js @@ -567,6 +567,25 @@ function initSyslogReports() { * Autocomplete Form Callback Functions * ======================================================================== */ +/** + * Validate and invoke a named callback function specified as a string + * @param {string} onChange - Name of the global function to call (e.g. 'myCallback') + */ +function runSyslogAutocompleteOnChange(onChange) { + if (typeof onChange !== 'string') { + return; + } + + var callbackName = onChange.trim().replace(/\(\)\s*$/, ''); + if (!callbackName.match(/^[A-Za-z_$][A-Za-z0-9_$]*$/)) { + return; + } + + if (typeof window[callbackName] === 'function') { + window[callbackName](); + } +} + /** * Initialize autocomplete for form dropdown fields * @param {string} formName - The name of the form field @@ -591,7 +610,7 @@ function initSyslogAutocomplete(formName, callback, onChange) { $('#' + formName).val(ui.item.value); } if (onChange) { - eval(onChange); + runSyslogAutocompleteOnChange(onChange); } } }).css('border', 'none').css('background-color', 'transparent'); diff --git a/tests/regression/issue260_remove_eval_callback_test.php b/tests/regression/issue260_remove_eval_callback_test.php new file mode 100644 index 0000000..9e3b3fb --- /dev/null +++ b/tests/regression/issue260_remove_eval_callback_test.php @@ -0,0 +1,45 @@ +